Sign in to follow this  
RokkumanXRX

SDL and Sprite Flipping

Recommended Posts

RokkumanXRX    122
Well, I've done some searching online, and surprisingly, I can't find much of anything, but is there a way in SDL to simply make a sprite facing left.... become a sprite facing right?

Share this post


Link to post
Share on other sites
Scanmaster_k    254
Well since you can get access to all the pixels you can do it yourself quite easily by moving the pixels from one surface to the other. Move the first pixel at 0,0 to the for example 32,0 if the image is 32 pixels wide.


Scanmaster_K

Share this post


Link to post
Share on other sites
Roots    1625
If you use OpenGL with SDL, its very easy to do. Things like that are one of the reasons we decided to invest in OpenGL, even though our game isn't really 3D.

Share this post


Link to post
Share on other sites
RokkumanXRX    122
Well, the game I'm working on is a fighting game, so flipping every single sprite and treating them as completely different sprites would be overly tedious. I'm sure it can't be that hard to turn a sprite around, considering it happens all the time.

But I think I'll go with adding OpenGL. I'm not very familiar with the library at all, so would you mind perhaps giving me an example code of doing so, in cooperation with SDL?

Share this post


Link to post
Share on other sites
Icefox    238
The canonical way of doing this in pure 2D is to have two different images/surfaces for the same sprite... one facing right, one facing left. Then which image you use is just a matter of moving a rect or pointer. Now your choice is whether to make all the direction-sprites ahead of time, or just flip/rotate the ones you have and then hang on to the surfaces.

Share this post


Link to post
Share on other sites
Roots    1625
Quote:
Original post by RokkumanXRX
Well, the game I'm working on is a fighting game, so flipping every single sprite and treating them as completely different sprites would be overly tedious. I'm sure it can't be that hard to turn a sprite around, considering it happens all the time.

But I think I'll go with adding OpenGL. I'm not very familiar with the library at all, so would you mind perhaps giving me an example code of doing so, in cooperation with SDL?



Read the NeHe tutorials. They have sample source code files archived there for the tutorials, including the use of SDL.

Share this post


Link to post
Share on other sites
by    100
Quote:
Original post by Lazy Foo
with basic SDL, no.

just flip them before hand using MSPaint or something.



No, its possible through "basic" sdl. me and a friend of mine did this a few weeks ago. i cant remember exactly but when i return to home i will post it.

Share this post


Link to post
Share on other sites
Lazy Foo    1113
Quote:
Original post by by
Quote:
Original post by Lazy Foo
with basic SDL, no.

just flip them before hand using MSPaint or something.



No, its possible through "basic" sdl. me and a friend of mine did this a few weeks ago. i cant remember exactly but when i return to home i will post it.


It's my tutorial 29.

Share this post


Link to post
Share on other sites
samuraicrow    325
Quote:
original text posted by RokkumanXRX
But I think I'll go with adding OpenGL. I'm not very familiar with the library at all, so would you mind perhaps giving me an example code of doing so, in cooperation with SDL?


There is a helper library called hxRender that may help. You can download it and a simple example of how to use it from the author's web page. Incidently, it will also speed up sprite rotations.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this