darkraziel Posted August 27, 2015 Share Posted August 27, 2015 Hi all, I have a simple question about phaser animations. Right now I'm working in a game where I animate some spheres that roll down a road. The animation frameRate depends on the sphere "speed", so if the spheres go faster the animation will move faster too and so on. I'm currently changing each sphere frame manually on the update method. To do this each sprite has an array with the frameNames.for (i = 0; i < 80; i++){ this.redOrbFrames.push('orb_red_' + i +'.png'); this.greenOrbFrames.push('orb_green_' + i +'.png'); this.blueOrbFrames.push('orb_blue_' + i +'.png'); this.goldOrbFrames.push('orb_gold_' + i +'.png'); this.purpleOrbFrames.push('orb_purple_' + i +'.png'); this.calypsoOrbFrames.push('orb_calypso_' + i +'.png'); this.blackOrbFrames.push('orb_black_' + i +'.png');}sphere.orbFrameNames = this.redOrbFrames.update(){ i++; this.frameName = this.orbFrameNames[i];}Something like that. I wanted to know if there's another way to do something like this by using phaser animations and if it would be more efficient performance-wise. Excuse the poor english and thanks for any help provided. Link to comment Share on other sites More sharing options...
drhayes Posted August 27, 2015 Share Posted August 27, 2015 When you add an animation to a sprite like this: "sprite.animations.add('idle', [0, 1, 2, 3, 4], 20);" it will hand you back an animation object. That animation object has a "speed" property that should do what you want. Link to comment Share on other sites More sharing options...
darkraziel Posted August 27, 2015 Author Share Posted August 27, 2015 Nice, I should test that to see if it works. I have another question though, is it possible to play the animation in reverse? for example by settings speed to a negative value? Link to comment Share on other sites More sharing options...
jdnichollsc Posted August 28, 2015 Share Posted August 28, 2015 Nice, I should test that to see if it works. I have another question though, is it possible to play the animation in reverse? for example by settings speed to a negative value? My example using Phaser and GSAP! http://codepen.io/jdnichollsc/pen/ZYeWEr Regards, Nicholls Link to comment Share on other sites More sharing options...
Nikow Posted August 28, 2015 Share Posted August 28, 2015 Like that : yourSprite.animations._anims.yourAnim.speed = speedYouNeed ;? Link to comment Share on other sites More sharing options...
Recommended Posts