SDL and Sprite Flipping

Started by
9 comments, last by samuraicrow 17 years, 11 months ago
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?
Advertisement
with basic SDL, no.

just flip them before hand using MSPaint or something.

Learn to make games with my SDL 2 Tutorials

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
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.

Hero of Allacrost - A free, open-source 2D RPG in development.
Latest release June, 2015 - GameDev annoucement

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?
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.
-----http://alopex.liLet's Program: http://youtube.com/user/icefox192
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.

Hero of Allacrost - A free, open-source 2D RPG in development.
Latest release June, 2015 - GameDev annoucement

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.
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.

Learn to make games with my SDL 2 Tutorials

Through SDL_gfx, you can rotate surfaces during runtime. Be warned though as it's extremely slow so you might want to cache the newly created surfaces.
Rob Loach [Website] [Projects] [Contact]

This topic is closed to new replies.

Advertisement