Phaser 3 动画顺序/优先级
Posted
技术标签:
【中文标题】Phaser 3 动画顺序/优先级【英文标题】:Phaser 3 Animation order/priority 【发布时间】:2021-06-11 18:56:47 【问题描述】:我目前正在尝试将动画添加到我的游戏中,直到现在还可以, 但现在我遇到了一个问题,我想我有点失去了概述。
我的控件: W - 查找 A - 向左走 D - 向右走 空间 - 跳跃 E 按住 - 冲锋射击(动画:在停留/奔跑/跳跃时按住枪) E 释放 - 射击
我的问题: 到目前为止,所有动画都很好,如果我使用任何控制键然后按 E。 问题是,如果我先按住 E 并 然后 按任何其他键,则当前动画不会改变。 如果我按任何键(例如向左走),按住 E 并在按住 E 的同时释放行走,则相同。 唯一的例外是,如果我先按住 E 再按 W。然后会播放查找动画。 但是如果我在按住 E 的同时释放 W,它会再次卡在查找动画中。
我的动画/播放器控制代码:
playerControlUpdate()
if (this.setUIOnce)
this.setUpUI();
this.setUIOnce = false;
//Fullscreen
if (Phaser.Input.Keyboard.JustDown(this.key_F))
if (this.scene.scale.isFullscreen)
this.scene.scale.stopFullscreen();
else
this.scene.scale.startFullscreen();
;
//movement
if (this.key_A.isDown)
this.setVelocityX(this.pace * -1);
this.setFlipX(true);
this.playerDirection = "left";
if (this.body.touching.down)
this.currentFrame = this.anims.currentFrame.index;
if (this.key_E.isDown)
if(this.anims.currentAnim.key == 'walkRight')
if (this.currentFrame >= 13 || this.currentFrame <= 0)
this.play( key: 'shootWalk', startFrame: 1 , true);
else
this.play( key: 'shootWalk', startFrame: this.currentFrame , true);
else
if (this.anims.currentAnim.key == 'shootWalk')
if (this.currentFrame >= 13 || this.currentFrame <= 0)
console.log(this.currentFrame);
this.play( key: 'walkRight', startFrame: 1 , true);
else
this.play( key: 'walkRight', startFrame: this.currentFrame , true);
else
this.anims.play('walkRight', true);
else if (this.key_D.isDown)
this.setVelocityX(this.pace);
this.setFlipX(false);
this.playerDirection = "right";
if (this.body.touching.down)
this.currentFrame = this.anims.currentFrame.index;
if (this.key_E.isDown)
if (this.anims.currentAnim.key == 'walkRight')
if (this.currentFrame >= 13 || this.currentFrame <= 0)
console.log(this.currentFrame);
this.play( key: 'shootWalk', startFrame: 1 , true);
else
this.play( key: 'shootWalk', startFrame: this.currentFrame , true);
else
if (this.anims.currentAnim.key == 'shootWalk')
if (this.currentFrame >= 13 || this.currentFrame <= 0)
console.log(this.currentFrame);
this.play( key: 'walkRight', startFrame: 1 , true);
else
this.play( key: 'walkRight', startFrame: this.currentFrame , true);
else
this.anims.play('walkRight', true);
else
this.setVelocityX(0);
if (this.body.touching.down && !this.key_E.isDown && this.anims.currentAnim.key != 'shootStay_release' && !this.anims.isPaused && this.anims.currentAnim.key != 'shootUp')
if (this.playerDirection == "left")
this.setFlipX(true);
this.anims.play('idle', true);
else if (this.playerDirection == "right")
this.setFlipX(false);
this.anims.play('idle', true);
if (this.key_W.isDown && !(this.key_A.isDown || this.key_D.isDown))
if (this.anims.currentAnim.key != 'shootUp' && this.body.touching.down)
this.anims.play('lookUp', true);
if (!this.body.touching.down)
this.currentFrame = this.anims.currentFrame.index;
if (this.key_W.isDown)
if (this.anims.currentAnim.key == 'jump' || this.anims.currentAnim.key == 'shootJump')
if (this.currentFrame >= 8 || this.currentFrame <= 0)
console.log(this.currentFrame);
this.play( key: 'upJump', startFrame: 1 , true);
else
this.play( key: 'upJump', startFrame: this.currentFrame , true);
else if (this.key_E.isDown)
if (this.anims.currentAnim.key == 'jump' || this.anims.currentAnim.key == 'upJump')
if (this.currentFrame >= 8 || this.currentFrame <= 0)
console.log(this.currentFrame);
this.play( key: 'shootJump', startFrame: 1 , true);
else
this.play( key: 'shootJump', startFrame: this.currentFrame , true);
else
if (this.anims.currentAnim.key == 'upJump' || this.anims.currentAnim.key == 'shootJump')
if (this.currentFrame >= 8 || this.currentFrame <= 0)
console.log(this.currentFrame);
this.play( key: 'jump', startFrame: 1 , true);
else
this.play( key: 'jump', startFrame: this.currentFrame , true);
if (Phaser.Input.Keyboard.JustDown(this.key_SPACE))
if (this.body.touching.down)
this.setVelocityY(this.jumpPower);
if (this.key_W.isDown)
this.anims.play('upJump', true);
else if (this.key_E.isDown)
this.anims.play('shootJump', true);
else
this.anims.play('jump', true);
//Weapons
if (Phaser.Input.Keyboard.JustDown(this.key_E))
this.bigShot = this.scene.time.now + 700;
if (this.key_W.isDown )
this.playAfterRepeat('lookUp');
else
if (this.anims.currentAnim.key != 'shootStay_release' && !this.anims.isPaused && !(this.key_A.isDown || this.key_D.isDown) && this.body.touching.down) // touching ground bei jumpshoot ggf anpassen
this.anims.play('shootStay_hold', true);
else
if (this.body.velocity.x == 0)
this.playAfterRepeat('shootStay_hold');
if (Phaser.Input.Keyboard.JustUp(this.key_E))
if (this.body.touching.down)
if (this.key_W.isDown)
this.anims.play('shootUp', true);
this.playAfterRepeat('lookUp');
else if (this.key_A.isDown || this.key_D.isDown)
else
this.anims.play('shootStay_release', true);
this.playAfterRepeat('idle');
if (this.weaponInUse == 1)
this.useWeaponOne();
else
this.useWeaponTwo();
if (Phaser.Input.Keyboard.JustDown(this.key_C))
if (this.weaponCD > this.scene.time.now) return; // big shot
else
this.weaponInUse = this.weaponInUse * -1;
this.scene.registry.set("playerWeaponInUse", this.weaponInUse); //später entfernen. Muss nur bei Szenenwechsel gespeichert werden (wenn überhaupt).
eventEmitter.emit('activeWeapon', this.weaponInUse);
eventEmitter.emit('weaponCD', this.weaponCooldown);
this.scene.time.addEvent(this.timedEvent);
this.weaponCD = this.scene.time.now + this.weaponCooldown;
if (Phaser.Input.Keyboard.JustDown(this.key_X))
我希望一些新的观点/观点可以帮助我。 :) 如果有人知道更好的动画排序方法,我也会很感激。 我知道我的订单非常……混乱。
【问题讨论】:
【参考方案1】:我认为问题出在play
函数中的第二个参数。此参数告诉移相器不要播放动画,当它已经在播放时(link to the documentation,或查看此answer)。
您可以删除参数或将其设置为false
(但仅限于拍摄动画和/或我认为有意义的地方)。
【讨论】:
以上是关于Phaser 3 动画顺序/优先级的主要内容,如果未能解决你的问题,请参考以下文章