Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

286
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda