点击 sprite 时 Pixi 没有改变位置

Pixi is not changing position when click on sprite

我正在尝试创建一个示例 pixi 应用程序。我有一张图片,当用户点击图片时,它应该移动它的位置。

var canvasWidth = window.innerWidth;
var canvasHight = window.innerHeight

var renderer = PIXI.autoDetectRenderer(canvasWidth, canvasHight);
document.body.appendChild(renderer.view);
var stage = new PIXI.Container();

PIXI.loader
    .add('images/sample.png')
    .add('images/background.jpg')
    .load(setup);

function setup() {
    var backGround = new PIXI.Sprite(
        PIXI.loader.resources["images/background.jpg"].texture);
    var steve = new PIXI.Sprite(
        PIXI.loader.resources["images/sample.png"].texture);
    backGround.hieght = canvasHight;
    backGround.width = canvasWidth;
    setPropertiesToSteve(steve);
    stage.addChild(backGround);
    stage.addChild(steve);
    renderer.render(stage);
}

// Function just to set properties for steve
function setPropertiesToSteve(steve) {
    steve.interactive = true;
    steve.position.x = canvasWidth/2;
    steve.position.x = canvasWidth/4;
    steve.on('pointerdown',function(){
        steve.position.x = steve.position.x + 10;
    });
}

但是当我点击对象时没有任何反应。我是 pixijs.SO 的新手,不知道如何处理。

您需要重新渲染舞台:) 看官方Pixi例子https://pixijs.github.io/examples/

他们使用 PIXI.Application class 来设置常见的东西,比如自动重新渲染你的舞台的自动收报机