Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Animation 如何仅在精灵在Phaser 3中移动时播放动画?_Animation_Game Physics_Phaser Framework_Matter.js - Fatal编程技术网

Animation 如何仅在精灵在Phaser 3中移动时播放动画?

Animation 如何仅在精灵在Phaser 3中移动时播放动画?,animation,game-physics,phaser-framework,matter.js,Animation,Game Physics,Phaser Framework,Matter.js,我在Phaser3中创建了一个游戏,使用物质物理学,就像我以前做的那样。然而,到目前为止,我从未遇到过一个涉及动画和动作的问题。我希望我的动画只在玩家移动时播放,在他停止移动时停止,就像真实游戏中的玩家一样 我尝试过各种各样的do-while循环,使用“animationcomplete”而不使用它。我还尝试过让我的动画循环(重复:-1)并将其设置为仅执行一次 我知道,.isDown跟踪按键,只要按下键,就会执行以下代码,而.JustDown只执行一次。我也不确定该用哪一个 动画代码 //An

我在Phaser3中创建了一个游戏,使用物质物理学,就像我以前做的那样。然而,到目前为止,我从未遇到过一个涉及动画和动作的问题。我希望我的动画只在玩家移动时播放,在他停止移动时停止,就像真实游戏中的玩家一样

我尝试过各种各样的do-while循环,使用
“animationcomplete”
而不使用它。我还尝试过让我的动画循环(
重复:-1
)并将其设置为仅执行一次

我知道,
.isDown
跟踪按键,只要按下键,就会执行以下代码,而
.JustDown
只执行一次。我也不确定该用哪一个

动画代码

 //Animations
        //Running right animation
        var runRightFrameNames = this.anims.generateFrameNames(
            'sheet', {start: 14, end: 16, zeroPad: 4,
            prefix : 'run_right/'}
        );
        this.anims.create({
            key: 'runRight', frames: runRightFrameNames, frameRate: 1, repeat: 0
        });
update()
函数中的当前代码,这不是我唯一尝试过的

        //If the right arrowkey is pressed
        if (this.arrowKeys.right.isDown) {
            //Move player
            this.hero.setVelocityX(5);
            //Play animation
            this.hero.anims.play('runRight');
            //When animation is done, stop hero
            this.hero.on("animationcomplete", () => {
                this.hero.setVelocityX(0);
            });
        }

您可以这样修改代码段:

//If the right arrowkey is pressed
if (this.arrowKeys.right._justDown) {
    console.log('Cursor right is pressed!');

    //Move player
    this.hero.setVelocityX(5);

    //Play animation
    this.hero.anims.play('runRight');

} else if (this.arrowKeys.right._justUp) {
    console.log('Cursor right is NOT pressed!');
}
编辑:

要修复英雄的动画,请更改此行this.hero.anims.play('runRight')
这个.hero.anims.play('runRight',true)

您还应将
repeat
值更改为
-1
,如下所示:

this.anims.create({
    key: 'runRight', frames: runRightFrameNames, frameRate: 6, repeat: -1
});

您可以这样修改代码段:

//If the right arrowkey is pressed
if (this.arrowKeys.right._justDown) {
    console.log('Cursor right is pressed!');

    //Move player
    this.hero.setVelocityX(5);

    //Play animation
    this.hero.anims.play('runRight');

} else if (this.arrowKeys.right._justUp) {
    console.log('Cursor right is NOT pressed!');
}
编辑:

要修复英雄的动画,请更改此行this.hero.anims.play('runRight')
这个.hero.anims.play('runRight',true)

您还应将
repeat
值更改为
-1
,如下所示:

this.anims.create({
    key: 'runRight', frames: runRightFrameNames, frameRate: 6, repeat: -1
});

我看到你的留言了,是的,我知道你需要什么。似乎物质物理学更难让它起作用。“我会继续挖的。”曼努埃拉巴斯卡明白了。我会继续在论坛上挖掘,我看到了你的信息,是的,我知道你需要什么。似乎物质物理学更难让它起作用。“我会继续挖的。”曼努埃拉巴斯卡明白了。我会继续在论坛上挖掘,我想和你们分享。我明天会尝试修复动画!谢谢你,我也会的。进步就是进步你可以睡觉了,我也要睡觉了。如果可以的话,我会在早上把一切整理好。我想和你分享一下。我明天会尝试修复动画!谢谢你,我也会的。进步就是进步你可以睡觉了,我也要睡觉了。如果可以的话,我会在早上把一切整理好