Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

96
Views
Phaser 3 - currentAnim no está definido

Estoy tratando de restablecer mi animación al cuadro 0 después de terminar. Para esto estoy usando el siguiente código:

gameState.idle.play('wag', true).on('animationcomplete', () => {gameState.idle.pause(gameState.idle.currentAnim.frames[0])});

Sin embargo, cuando intento esto me sale el error

TypeError no detectado: gameState.idle.frames no está definido

¿Cómo puedo arreglar esto?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Si solo desea saber cómo obtener el primer cuadro de la animación actual, puede (si el código publicado es correcto y lo interpreté correctamente) :

 gameState.idle.play('wag', true).on('animationcomplete', (currentAnim) => { gameState.idle.pause(currentAnim.frames[0]) });

Esto debería funcionar. aquí el enlace a la documentación, explica los parámetros del evento ANIMATION_COMPLETE . ( https://photonstorm.github.io/phaser3-docs/Phaser.Animations.Events.html#event:ANIMATION_COMPLETE )

Si no desea utilizar el parámetro pasado a los eventos, puede utilizar este código:

 gameState.idle.play('wag', true).on('animationcomplete', () => { gameState.idle.pause(gameState.idle.anims.currentAnim.frames[0]) });

También funciona, pero no es tan fácil de leer.

bajo el supuesto de que gameState.idle es un Phaser.GameObjects.Sprite

Actualización (con código de jsfiddle de los comentarios):

la función de pause no es una función del objeto Sprite, es una función de las propiedades Phaser.Animations.AnimationState del Sprite :

 const gameState = { gameWidth: 400, gameHeight: 200, menu: {}, textStyle: { fontFamily: "'Comic Sans MS'", fill: "#fff", align: "center", boundsAlignH: "left", boundsAlignV: "top", wordWrap: true, wordWrapWidth: 300 } }; function preload() { //this.load.baseURL = 'assets/'; //this.load.atlas('idle', 'idle.png', 'idle.json'); // added Image from an official phaser example, for a working example this.load.spritesheet('idle', 'https://labs.phaser.io/assets/animations/brawler48x48.png', { frameWidth: 48, frameHeight: 48 }); } function create() { this.anims.create({ key: "wag", frameRate: 8, frames: this.anims.generateFrameNumbers("idle", { start: 0, end: 5}), repeat: 0, }); gameState.idle = this.add.sprite(200, 100, "idle"); gameState.idle.setInteractive({cursor: 'url("assets/pet.cur"), pointer'}); } function update() { let test = Math.floor(Math.random() * (50) + 1); if (test == 50) gameState.idle.play('wag', true).on('animationcomplete', (currentAnim, frame, gameObject) =>{ gameObject.anims.pause(currentAnim.frames[0]); }); } var config = { backgroundColor: "0xf0f0f0", scale: { width: gameState.gameWidth, height: gameState.gameHeight, autoCenter: Phaser.Scale.CENTER_BOTH }, scene: { preload, create, update } }; var game = new Phaser.Game(config);
 <script src="https://cdn.jsdelivr.net/npm/phaser@3.55.2/dist/phaser.js"></script>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!