Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why SFML position is float?

Tags:

c++

sfml

On SFML documentation I see that position of Sprites and shapes is... float. Why? Is it linked with sf::View, which bounds are float too?

Links to documentation:

sf::Transformable

sf::View

sf::RenderWindow

like image 656
senghe Avatar asked Jun 30 '26 09:06

senghe


1 Answers

You need floating points in order to animate you sprites correctly. Imagine a position at x=1, and you increase the position based on your delta time to 1.1. It would take 10 frames to move your sprite to x=2 (next pixel). Using integers x would be rounded to 1, and you won't move at all.

Besides that, in order to render stuff, you have to calculate the transform matrix (using floats), so you had to convert to floats sooner or later anyways. This is how graphics API's work internally, SFML simply wraps everything up so you only have to worry with screen coordinates (pixels, in that case).

like image 145
dan Avatar answered Jul 06 '26 02:07

dan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!