gpt4 book ai didi

javascript - 在 Phaser 3 中设置快照的位置

转载 作者:行者123 更新时间:2023-12-04 03:41:14 27 4
gpt4 key购买 nike

我正在使用 this Phaser 3 example我需要在预定义的位置显示快照。目前,每个快照都显示在正文下方,带有 document.body.appendChild(image);

我尝试了 this.add.sprite(0, 0, image).setOrigin(0.5,0); 但它返回错误:

Uncaught TypeError: Cannot read property 'add' of null

代码:

  this.input.on('pointerdown', function (pointer) {

var textureManager = this.textures;

this.game.renderer.snapshotArea(pointer.x, pointer.y, 128, 128, function (image)
{
document.body.appendChild(image);

if (textureManager.exists('area'))
{
textureManager.remove('area');
}

textureManager.addImage('area', image);

particles.setTexture('area');
});

}, this);

最佳答案

我在正文末尾留下了附加图像的部分,但您可以根据需要随意编辑。

var snapshot
var lastpointer = {x: 100, y: 100}
this.input.on('pointerdown', (pointer) => {
var textureManager = this.textures;
this.game.renderer.snapshotArea(pointer.x, pointer.y, 128, 128, (image) => {
lastpointer.x = pointer.x
lastpointer.y = pointer.y
document.body.appendChild(image);

if (textureManager.exists('area'))
{
textureManager.remove('area');
}

textureManager.addImage('area', image);

particles.setTexture('area');

// Add the snapshot to the texture cache
if (textureManager.exists('snapshot'))
{
textureManager.remove('snapshot');
snapshot.destroy();
snapshot = null;
}
textureManager.addBase64('snapshot', image.src);
});

}, this);

// When the snapshot is actually loaded, add it to the pointer coordinates (or simply fixed ones)
this.textures.on('addtexture', function (texture) {
if('snapshot' === texture) {
snapshot = this.add.image(lastpointer.x, lastpointer.y, 'snapshot');
}
}, this);

关于javascript - 在 Phaser 3 中设置快照的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65994558/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com