jrrantolin Posted May 18, 2015 Share Posted May 18, 2015 This is from the "animation event" example library in phaser. I'm trying to make the mummy walk for 3 loops of the walk animation to the right, then have the mummy walk for 3 loops to the left and repeat continuously so that he is pacing back and forth with the background in synch so that it looks like the mummy is moving through the scene.I know that to move the mummy to the left you can do mummy.scale.x *= -1;I don't have any experience in coding whatsoever so I'm learning by playing around with the code and testing it. I'm not sure how to loop the mummy back and forth. How can I do that?var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });function preload() { game.load.image('thorn_lazur', 'thorn_lazur.png'); game.load.spritesheet('metalslug_mummy37x45', 'metalslug_mummy37x45.png', 37, 45, 18);}var back;var mummy;var anim;var loopText;function create() { back = game.add.image(0, -400, 'thorn_lazur'); back.scale.set(2); back.smoothed = false; mummy = game.add.sprite(200, 360, 'metalslug_mummy37x45', 5); mummy.scale.set(4); mummy.smoothed = false; anim = mummy.animations.add('walk'); anim.onStart.add(animationStarted, this); anim.onLoop.add(animationLooped, this); anim.onComplete.add(animationStopped, this); //controls how fast the mummy walks anim.play(10, true);}function animationStarted(sprite, animation) { game.add.text(32, 32, 'Animation started', { fill: 'white' });}function animationLooped(sprite, animation) { if (animation.loopCount === 1) { loopText = game.add.text(32, 64, 'Animation looped', { fill: 'white' }); } else { loopText.text = 'Animation looped x2'; animation.loop = false; }}function animationStopped(sprite, animation) { game.add.text(32, 64+32, 'Animation stopped', { fill: 'white' });}function update() { if (anim.isPlaying) { back.x -= 1; }} Link to comment Share on other sites More sharing options...
Recommended Posts