Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SOLVED]Variable rendering and renderwindow.draw  (Read 2201 times)

0 Members and 1 Guest are viewing this topic.

Programmer001

  • Newbie
  • *
  • Posts: 7
    • View Profile
[SOLVED]Variable rendering and renderwindow.draw
« 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!
« Last Edit: August 26, 2015, 08:56:38 am by Programmer001 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Variable rendering and renderwindow.draw
« Reply #1 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.
Laurent Gomila - SFML developer

Programmer001

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Variable rendering and renderwindow.draw
« Reply #2 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


Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: [SOLVED]Variable rendering and renderwindow.draw
« Reply #3 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);
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Programmer001

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: [SOLVED]Variable rendering and renderwindow.draw
« Reply #4 on: August 27, 2015, 01:52:32 am »
 :o Haha, that would certainly work wouldn't it.