En el marco Phaser 3, ¿qué sintaxis utilizo para verificar el índice de cuadro actual?
Quiero hacer que aparezca un área de impacto solo cuando la hoja de sprites del jugador alcance cierto índice (el índice que muestra el movimiento de 'ataque'). Quiero lograr esto mediante la detección de su índice de cuadro actual.
¿Cómo puedo hacer esto?
Puede usar los eventos de sprite como: Phaser.Animations.Events.ANIMATION_UPDATE , detalles en la documentación oficial de Phaser
player.on(Phaser.Animations.Events.ANIMATION_UPDATE, function (anim, frame, gameObject, frameKey) { // Here you can check for the specific-frame if(frameKey == "show_hit_area_frame"){ // ... show hitarea } // alternatively: with the index of the frame if(frame.index == 7){ // ... show hitarea } });En este Evento seleccionado, también puede verificar el cuadro actual, para otras propiedades del objeto del cuadro ( detalles en la documentación oficial ), si no conoce/tiene la clave/índice de cuadro específico.
La solución se encuentra. //solución de hitbox: https://newdocs.phaser.io/docs/3.52.0/Phaser.Animations.Events.ANIMATION_COMPLETE_KEY
//hitboxB listener gameState.playerB.on('animationstart-kill', function () { console.log("finish kill <3") gameState.hitBoxB.x = gameState.playerB.flipX ? gameState.playerB.x + 120 : gameState.playerB.x - 120; gameState.hitBoxB.y = gameState.playerB.y; // gameState.hitBoxB.visible = true; }) gameState.playerB.on('animationcomplete-kill', function () { console.log("kill <3") gameState.hitBoxB.x =0 ; gameState.hitBoxB.y = 0; // gameState.hitBoxB.visible = false; })