darkraziel

Change animation frameRate dynamically

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.