The speed from a spritemap[SOLVED]


(billy2000) #1

So i have a spritemap with 4 frames, the FPS is 60.I whant to make the spritemap to complete the animation in exact 32 frames. I cant get the correct speed number …can someone help me? >.<


(Ultima2876) #2

Are you using a fixed or variable timestep?


(billy2000) #3

The variable is fixed


(billy2000) #4

actually is just like this:

playerSpritemap.add("push_down", [21, 22, 23, 24], speed, true);//I dont know how much would speed variable be.

(Ultima2876) #5

What I mean is, in your super() call in Main.as, do you pass ‘true’ to the fixed timestep argument? Timing stuff works differently depending on whether your game is running on a fixed timestep or a variable one.


(Jacob Albano) #6

Where count is the number of frames in your animation, and frames is the number of frames you want the animation to finish in:

var count:Number = 4;
var frames:Number = 32;
var speed:Number = (FP.assignedFrameRate * count) / frames;

Whether you have a fixed or variable timestep doesn’t affect it.


(billy2000) #7

Such a nice function u got there O: . Nice ty. And Ultima…well yeah it wasnt fixed >.<. Thx guys very helfull and fast replys like allways :D.


(Ultima2876) #8

Just for reference, fixed vs variable timestep does actually affect the speed you need to set for your spritemap animations as I originally thought. If you set a speed of 15 frames per second in variable mode, you must set (1 / FP.assignedFrameRate) * 15 in fixed mode to get the same result. It seems to be undocumented but I have tested it just now.

@jacobalbano’s solution would animate super fast in fixed timestep mode but works perfectly in variable timestep mode. To get it working in fixed timestep, use:

var count:Number = 4;
var frames:Number = 32;
var speed:Number = FP.fixed ? count / frames : (FP.assignedFrameRate * count) / frames;

(Jacob Albano) #9

I have no idea why that would matter, but apparently it does. That seems like a bug in FlashPunk more than anything related to user code though.


(Ultima2876) #10

Yeah, it’s the same with a lot of the timing stuff. Basically, try switching your game from variable to fixed time timestep at the end of development and you’ll see what I mean - it’ll be completely fubar!


(Zachary Lewis) #11