在Phaser 3中设置快照的位置

汤姆

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

我试过了,this.add.sprite(0, 0, image).setOrigin(0.5,0);但是返回了一个错误:

未捕获的TypeError:无法读取null的属性“ add”

代码:

  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);
Nemoverflow

我将附加图像的部分留在了主体的末端,但是随时可以根据需要进行编辑。

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);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章