Usando botão para correr com Phaser JS - Skate Platformer Game Devlog #05
Escrito em 26 de setembro de 2020 - JogosFala pessoal, no Game Devlog dessa semana vou mostrar como eu fiz para implementar a movimentação do hero em cima do skate, que é ativada quando você aperta o botão direcional duas vezes rapidamente, uma ótima idéia dada pelo Ítalo!
E abaixo o código que cuida da lógica do estado de corrida do hero.
// Handle hero running
if (!isJumping) {
if (this.runTimer <= 0) {
if (pressedRight || pressedLeft) {
this.pressedRunRight = pressedRight;
this.pressedRunLeft = pressedLeft;
this.runTimer = 1;
}
} else if (this.runTimer <= 10) {
if (this.pressedRunRight && isRightDown && pressedRight) {
this.setHeroState(RUNNING_RIGHT_START);
this.scene.time.delayedCall(
this.startRunDuration,
() => {
this.setHeroState(RUNNING_RIGHT);
}
);
} else if (this.pressedRunLeft && isLeftDown && pressedLeft) {
this.setHeroState(RUNNING_LEFT_START);
this.scene.time.delayedCall(
this.startRunDuration,
() => {
this.setHeroState(RUNNING_LEFT);
}
);
}
} else {
this.runTimer = 0;
this.pressedRunRight = false;
this.pressedRunLeft = false;
}
if (this.runTimer > 0) {
this.runTimer += 1;
}
}
const isRunning = this.isHeroRunning();
Tags: