Reputation: 488
I'm making a vertical-scroll platformer game, and I want to create sprites that move left-to-right (or right-to-left) and when they're out of the screen, they appear on the other side.
I have an implementation that is mostly working, the only problem is that the sprites on a single floor keeps getting closer and closer in every loop.
I'm really not good in describing things, so please check this video.
I'm using the following code to calculate the new position of the nodes:
pos.x = fmodf(size.width + pos.x + this->currentDir * this->speed * delta, this->len + size.width) - size.width;
len
is the width after which the sprite gets repositioned to 0
(actually -size.width
, which is the width of the sprite), currentDir
is either 1
or -1
and delta
is the time from the update() method.
Every sprite is positioned in it's own update(), but I already tried doing everything in the Scene's update() method, but the result was the same.
Upvotes: 0
Views: 114
Reputation: 7391
If your delta variable is increasing over time, then I believe that your pos.x would also increase in the same proportion, this is why the distance from the floors would change.
Have you tried to reset the delta value each time the floor goes offscreen?
Upvotes: 0