在Phaser js中添加精灵

abh*_*lpm 8 javascript phaser-framework

我需要知道如何相应地向左,右和向上(顶部)运动添加此精灵图像的第2行,第3行,第4行.

下面的代码是底部移动,作为精灵的第一行,我能够移动它.

如果我水平创建一个长精灵,我可以实现它,还有其他方法吗?

请帮我弄清楚如何包括第二排.

精灵图片(用户/播放器):精灵图像(用户,播放器)

function preload(){
    myGame.load.spritesheet('user', 'user4.png', 95, 158, 12);
}
var player;

function create(){
    player = myGame.add.sprite(500, 100, 'user');
    myGame.physics.arcade.enable(player);
    player.animations.add('bottom', [0,1,2,3,4,5,6,7,8,9,10,11], 12, true, true);

}

function update(){
        if (cursors.left.isDown) {
            //  Move to the left
            player.body.velocity.x = -150;
            player.animations.play('left');
        }
        else if (cursors.right.isDown)
        {
            //  Move to the right
            player.body.velocity.x = 150;
            player.animations.play('right');
        }
        else if (cursors.up.isDown)
        {
            //  Move to the right
            player.body.velocity.y = -50;
            player.animations.play('top');
        }
        else if (cursors.down.isDown)
        {
            //  Move to the right
            player.body.velocity.y = 50;
            player.animations.play('bottom');
        }
}
Run Code Online (Sandbox Code Playgroud)

Pho*_*orm 12

只需按照底部的方式定义额外的动画:

player.animations.add('bottom', [0,1,2,3,4,5,6,7,8,9,10,11], 12, true, true); player.animations.add('left', [12,13,14,15,16,17,18,19,20], 12, true, true); player.animations.add('right', [21,22,23,24,25,26,27,28,29], 12, true, true);

等等.显然我只是猜到了上面的帧数,你需要将它们纠正为你真正需要的.但是一旦你完成了这个,你就可以调用play动画键.