The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Rotating sprites?
Plazmotech


Joined: 21 Aug 2013
Posts: 9
I'm creating a top-down shooting game. I need to rotate the character to always face the mouse. How do I rotate textures or surfaces? It needs to be as fast as possible, as I'm trying to make this game very optimised.
Rotating sprites?
Alex Szpakowski
Guest

SDL_RenderCopyEx has angle and center arguments. It’s the most efficient way to do that with the SDL_Render API.

On Apr 12, 2014, at 7:14 PM, Plazmotech wrote:
Quote:
I'm creating a top-down shooting game. I need to rotate the character to always face the mouse. How do I rotate textures or surfaces? It needs to be as fast as possible, as I'm trying to make this game very optimised.
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Rotating sprites?
arosian


Joined: 22 Oct 2013
Posts: 13
As Alex noted, you can use SDL_RenderCopyEx. Check the wiki documentation:

https://wiki.libsdl.org/SDL_RenderCopyEx

On 4/12/2014 6:16 PM, Alex Szpakowski wrote:

Quote:
SDL_RenderCopyEx has angle and center arguments. It’s the most efficient way to do that with the SDL_Render API.

On Apr 12, 2014, at 7:14 PM, Plazmotech wrote:
Quote:
I'm creating a top-down shooting game. I need to rotate the character to always face the mouse. How do I rotate textures or surfaces? It needs to be as fast as possible, as I'm trying to make this game very optimised.
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




Quote:
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Rotating sprites?
Jonny D


Joined: 12 Sep 2009
Posts: 932
SDL_gpu uses an additional optimization that the SDL_Renderer system doesn't yet use (geometry batching).  If you actually run into performance problems, you might want to try it out.


As for implementing a facing effect in 2D, look at atan2() in the C math library.  It's so good.


Jonny D