Moving Sprite += with FrameChange

For questions about using Classic.

Post » Thu Aug 11, 2011 11:52 am

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!Shindoh2011-08-11 11:57:16
B
3
G
1
Posts: 70
Reputation: 615

Post » Thu Aug 11, 2011 1:33 pm

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

if Xbox360GamePad.LeftThumbstickX(1) > 0:
Trigger once while true
Player.SetAnim(walk)newt2011-08-11 13:33:50
Image Image
B
161
S
48
G
91
Posts: 7,359
Reputation: 67,273

Post » Fri Aug 12, 2011 11:06 am

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.
B
3
G
1
Posts: 70
Reputation: 615

Post » Fri Aug 12, 2011 11:22 am

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


B
9
S
2
G
4
Posts: 346
Reputation: 2,726

Post » Fri Aug 12, 2011 3:04 pm

As I remember, 1 px per second equal to 100*timedelta, so 10 px should be 1000*timedeltaDtrQ2011-08-12 15:20:34
B
2
S
2
G
2
Posts: 158
Reputation: 1,366

Post » Fri Aug 12, 2011 4:16 pm

[QUOTE=DtrQ] As I remember, 1 px per second equal to 100*timedelta, so 10 px should be 1000*timedelta[/QUOTE]
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.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 7 guests