Vocojax Posted November 1, 2017 Share Posted November 1, 2017 So I'm running into this problem where I initialize a sprite with multiple animations, but only the animation specified in the creation of the sprite is ever played. When I attempt to update the sprite with a new animation, it simply changes the framerate. I have debugged the game to see if it is actually updating the currentAnim, and it is. Also, I have tested the other animations too see if they loaded correctly by inputting them into the initializing sprite animation. Now, code: player = this.game.add.sprite(400, 400, 'player_idle'); this.game.physics.p2.enable(player, false); player.body.fixedRotation = true; player.animations.add('player_idle'); player.animations.add('player_left'); player.animations.add('player_right'); controls.left.onDown.add(() => { console.log("Begin left: " + player.animations.currentAnim.name); player.animations.play('player_left', 14, true); console.log("End left: " + player.animations.currentAnim.name); }, this); controls.right.onDown.add(() => { console.log("Begin right: " + player.animations.currentAnim.name); player.animations.play('player_right', 14, true); console.log("End right: " + player.animations.currentAnim.name); }, this); update() { player.body.setZeroVelocity(); controls.up.isDown ? player.body.moveUp(200) : null controls.down.isDown ? player.body.moveDown(200) : null controls.left.isDown ? player.body.moveLeft(200) : null controls.right.isDown ? player.body.moveRight(200) : null if(!controls.left.isDown && !controls.right.isDown && !controls.up.isDown && !controls.down.isDown) { player.animations.play('player_idle', 3, true); } } I am using "[email protected]". I need some help. Thank you a bunch. Link to comment Share on other sites More sharing options...
samme Posted November 1, 2017 Share Posted November 1, 2017 You need the frames argument in animations.add. Link to comment Share on other sites More sharing options...
Vocojax Posted November 1, 2017 Author Share Posted November 1, 2017 If it's null, then apparently all frames will be used. Can you clarify why I need to add that argument? Link to comment Share on other sites More sharing options...
samme Posted November 1, 2017 Share Posted November 1, 2017 If all three animations use every frame, they'll be identical. See, eg, http://phaser.io/examples/v2/animation/two-frame-test. Link to comment Share on other sites More sharing options...
Vocojax Posted November 1, 2017 Author Share Posted November 1, 2017 Thank you. This helps a bunch. I should have specified that the animations are separate. As in, I have separate sprite sheets for move left, right, etc. Would this be the root of the problem? If so, do you think this should be an enhancement in 3.0? Link to comment Share on other sites More sharing options...
samme Posted November 2, 2017 Share Posted November 2, 2017 Yes, I think you'll be much better off using one spritesheet. That's what Phaser anticipates and it's more efficient. I don't know what's planned for Phaser 3, but only one texture per animation is still a good rule. Link to comment Share on other sites More sharing options...
Recommended Posts