How do I Make My sprite entirely delta dependent

0 favourites
  • 4 posts
From the Asset Store
A set of 10 pixel art animated magic effects with icons. 2 Fire, 2 Earth, 2 Wind, 2 Water, Portal, Explosion.
  • Hi I was wondering how do i make my characters animations bind to a delta timescale? Is it already based on delta and not fps?

    Things like jump height and acceleration would be helpful bound to a delta timescale, rather than try to reinvent the acceleration of a jump, sustain, etc.

    Here is some stuttering that affects my gameplay

    http://www.filedropper.com/almostbasic

    This is my capx

  • The built in animation is by frame, so each frame rendered will progress the animation by one frame.

    You want to set the animation speed to 0, and use events to progress the animation.

    Every tick - Set Sprite.AnimationVariable to Sprite.AnimationVariable+60*dt

    Every tick - Set Sprite.AnimationFrame to floor(Sprite.AnimationVariable)

    This assumes you want it to run at 60 animation frames per second. You need a variable and Floor is to round down to the nearest whole number. You can use ceil() to round up instead.

    To Loop

    If Sprite.AnimationVariable > Sprite.AnimationFrameCount - Set Sprite.AnimationVariable to floor(0+Sprite.AnimationVariable%Sprite.AnimationFrameCount)

    Use modulo (%) - this will give you the remainder of a division. In this case, its how much you overshot total frames by.

    Depending on how fast you want the animation to play, you might have skipped animation frames if the target device is running at a very low fps. Could be desired though!.

  • First of all i want to say thank you for replying, and in thorough fashion. Im confused about animation variable and floor ceil() and looping.

    Basically im an idiot. I have a hunch you're giving me the right info i just have no idea

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • No need to put yourself down! Everyone has to start somewhere.

    So a normal animation usually runs one animation frame per system frame. So the speed is dependent on your system frame, or fps.

    By using Sprite.AnimationVariable+60*dt, your animation will progress at 60 frames per second regardless of what your system fps is. If your fps is lower than 60, some frames will be skipped. Or you can use 10*dt for 10 frames a second.

    The problem is that you can only set a whole number as an animation frame, like frame 1, 2, or 3. You cannot have a frame 3.248. The dt expression will start giving you fractional numbers. So to get past this we use either floor(), which means round down, and ceil() (ceiling), which rounds up. Floor(3.5) = 3, ceil(3.5) = 4.

    This gives us a new problem though - if I just use the animation frame and add to it, it might keep rounding down, preventing the animation from progressing! For example, I'm on frame 2, and dt adds .9 on tick. This 2.9 gets rounded down to 2. Next tick, I add .7 - this 2.7 also gets rounded down to 2.

    This is why we need a separate variable to keep track of our progress. As in the previous example, If I stored the 2.9 in a variable, this tick would show animation frame 2, then next tick I add .7 to 2.9 resulting in 3.6, this would show frame 3.

    Looping -

    Sprite.AnimationFrameCount gives you how many frames an animation is, lets say 13. Normally, it would progress from 0, 1, 2, and so on until 13. Then instead of 14, which doesn't exist, it would go back to 0. Now we have the same problem as above when using dt - we get decimals instead of whole numbers. If we progress from 13.7 to 14.5, we want to carry over that .5 when we go back to the beginning. You can do this with modulo. 14.5%14=0.5

    So basically the loop event I described as above goes like this:

    If my current AnimationVariable (14.5) is greater than AnimationFrameCount+1 (14. I didn't have +1 above but should have since we're rounding down), set AnimationVariable to 0 + whatever is leftover after 14 (14.5%14=0.5). Then of course we would need to round down to set the actual animation frame which is 0. But the next tick would continue adding from 0.5.

    This is a bit past beginner territory, so don't be discouraged if you don't get it. Good luck with your project!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)