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

Author Topic: Sprite rotation  (Read 1212 times)

0 Members and 1 Guest are viewing this topic.

Jan

  • Newbie
  • *
  • Posts: 2
    • View Profile
Sprite rotation
« on: September 21, 2012, 01:58:46 pm »
Hi,

for my top-down, tile-based 2d game, I have a png (16x16) with a circle and a small line (something like this: o- ) representing the player. The line pointing out of the circle is pointing to the direction the player is walking. At this moment i just rotate the sprite according to the player's walking direction (if player is walking from (0,0) to (10,10) i rotate 45 degrees). The rotation angle can be any float between 0 and 360 degrees. I noticed that if the sprite is rotated around an angle which is not a multiple of 90 degrees, the result looks really bad. I was wondering how the rotation works? Is every pixel just rotated (which probably results in rounding errors which explain the bad results), or is there a smarter algorithm behind (eg rotating corners + scanline algorithm)?

And more general: i have 2 zooming levels. Is it a good idea to make the sprites in high res (eg 256x256) and let the scaling do it's work, or is it better to have a 16x16 and 32x32 png file for each object? Or is it even better to use the sfml shape api to draw the simple shapes (after all, it's just a circle and a line)?
Thanks for the help

Jan

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Sprite rotation
« Reply #1 on: September 21, 2012, 02:17:18 pm »
The rotation is handled by OpenGL, so I can't tell you what it does exactly. But according to how graphics cards work, it should first transform (rotate) the sprite's rectangle, and then rasterize it with scanlines.

Note that calling texture.setSmooth can make the result better, I don't know if you tried yet.

Quote
And more general: i have 2 zooming levels. Is it a good idea to make the sprites in high res (eg 256x256) and let the scaling do it's work, or is it better to have a 16x16 and 32x32 png file for each object?
It depends. SFML uses either "nearest point" (setSmooth(false)) or "bilinear filtering" (setSmooth(true)) to display the scaled sprite. If you think you can use a better algorithm for preprocessing your image, and if it makes a significant difference, then do it ;)

Quote
Or is it even better to use the sfml shape api to draw the simple shapes (after all, it's just a circle and a line)?
Maybe. You should test and see what's the best solution for you.
Laurent Gomila - SFML developer

Jan

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Sprite rotation
« Reply #2 on: September 21, 2012, 04:01:27 pm »
Smoothing worked like a charm, thanks!  :)

I will try the shape api later, but I'm afraid that the fake 3d effect, which i have in my png's, will be hard to recreate.

Jan

 

anything