Moving Sprite += with FrameChange

This forum is currently in read-only mode.
From the Asset Store
Minimal Sprite Font with Stroke for Pixel Art games.
  • As long as I press in one direction with the Thumbstick of a Controller:

    • The walking animation is played.
    • Every next frame of the animation the sprite should move += 10px.
    • I want to keep the game V-Synced.

    Right now, my code is:

    if Xbox360GamePad.LeftThumbstickX(1) > 0:

       Player.SetAnim(walk)

       if Player.OnAnimFrameChange():

          Player.X += 10

    The walk animation's own speed is set to 16fps in its own settings.

    But what happens now, the Sprite seems to move with the V-Sync speed, instead of the 16fps. Way too fast.

    What did I oversee here?

    Thanks in Advance!

  • Your saying if the state is 0, constantly set the animation.

    if Xbox360GamePad.LeftThumbstickX(1) > 0:

    Trigger once while true

    Player.SetAnim(walk)

  • Hey newt, thanks for Your quick reply!

    I think You misunderstood my problem. In fact the animation plays fine this way, although I see that Your code should actually be the right one when I think about it? lol; I mean it doesn't keep displaying the first frame of animation with my code, it plays normally and loops.

    Anyway, my problem was not with the display of the animation, but the correct movement in time, relative to the animations original fps. It was animated to be seen with 16fps.

    That means, the sprite should only move forward in X, when it changes frames to the next frame in its loop.

    Now the application itself is set to run with V-Sync.

    The animation itself in its "animators properties" area is set to run with 16fps.

    So, as long as the Thumbstick is held in the forward direction, the walking animation will be playing, it will play with it's own fps set in the animator and should be move forward in X, every time the frame changes.

  • I don't believe the animation speed is tied to the fps.

    However, to work in V sync you need to multiply by timedelta. Have a search if the forum will let you, there are a few threads where it is explained well(one of those threads teaching me about timedelta)

    So it would look like this. It would move 10 pixels a second, which might be too slow, but you will need to work out what rate is correct.

    Player.X += 10 * timedelta

  • As I remember, 1 px per second equal to 100*timedelta, so 10 px should be 1000*timedelta

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • As I remember, 1 px per second equal to 100*timedelta, so 10 px should be 1000*timedelta

    This is wrong.

    One can either move pixel-based or time-based. If you move time-based then

    distance per second = n * TimeDelta

    This is true to every framerate. If you tell a Sprite to move

    +Always

    -> Sprite: Set X to .X + 20 * TimeDelta

    It will move by 20 pixel per second to the right, no matter the framerate.

    However, Shindoh decided to move pixel-based. No matter the time, on every frame change move

    .X + 10

    Shindoh, I didn't recognize a misbehavior when trying to recreate the issue. Without a cap I can't help much. But make sure the animation is not retriggered on every tick (like it is in the code example of your first post). Also make sure, the "frame speed" property of the individual frames of the animation is set to 1.

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