SFML community forums

Help => Graphics => Topic started by: Programmer001 on August 26, 2015, 08:39:00 am

Title: [SOLVED]Variable rendering and renderwindow.draw
Post by: Programmer001 on August 26, 2015, 08:39:00 am
Hey all,

I'm experimenting with different game loops. I've got one set up similar to deWitters Game Loop "Constant Game Speed independent of Variable FPS." Display() gets passed an interpolation value based on where the game is between frames.

So if "Actor" was at 500px in frame 1 and 600px in frame 2, and display() gets called in between the two frames then it should draw "Actor" at 550px despite that not being its actual position.

Bottom line, I'm trying to figure if I can have SFML draw an object offset from its actual position, without changing its actual position to make this concept work.

I'm still learning all the great features SFML has so maybe I missed it. Currently I've just been using something like: window.draw(actor);

Can this be done with Transforms or some other method?

Thank You!
Title: Re: Variable rendering and renderwindow.draw
Post by: Laurent on August 26, 2015, 08:45:57 am
sf::Transform transform;
transform.translate(50, 0);
window.draw(actor, transform);

But... this is probably the wrong approach. You'd better separate the visual position from the physical position, ie. not use the sprite's position for both. The sprite's position represents where the sprite is on screen, period. If your logic / physics / whatever needs a different position, then use a different pair of coordinates and keep the sprite's position for where you want to draw it.
Title: Re: Variable rendering and renderwindow.draw
Post by: Programmer001 on August 26, 2015, 08:56:13 am
Simple. I like the alternate approach as well, it wouldn't be that hard to implement.

Thanks for the speedy reply

Title: Re: [SOLVED]Variable rendering and renderwindow.draw
Post by: Hapax on August 26, 2015, 08:32:46 pm
Although I fully support and agree with Laurent's method (and is the way I would do it), I just wanted to answer the specific question about temporarily offsetting for a draw, even though you probably won't need it anymore  ;D (and it's questionable practice)

It is simply:
sprite.move(offset);
window.draw(sprite);
sprite.move(-offset);
Title: Re: [SOLVED]Variable rendering and renderwindow.draw
Post by: Programmer001 on August 27, 2015, 01:52:32 am
 :o Haha, that would certainly work wouldn't it.