Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

285
Visualizações
How to play an animation only if there isn't one yet in Phaser?

What I want to do is play a running animation on a sprite, every time a key is pressed

My code (extract) looks like this:


function update() {
  if (keys["w"].isDown) {
    avatar.setVelocityY(-250);
  }
  if (keys["d"].isDown) {
    avatar.setVelocityX(250);
  }
  if (keys["a"].isDown) {
    avatar.setVelocityX(-250);
  }
  if (keys["s"].isDown) {
    avatar.setVelocityY(250);
    avatar.play("run_front");
  }
}

The problem: When I hit s, only the first frame of the animation is played and the animation will only finish when I stop pressing it.

I think this is because the animation is overwritten every time I press s.

So how can I run the animation only if the one before isn't playing yet?

Thanks in advance

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

I found the solution in using avatar.anims.isPlaying

So what I did is:

    if (!avatar.anims.isPlaying) avatar.anims.play("lazy");


about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda