First off, i'm not sure if this is in the correct section of the forum, so if it's not, sorry, please move it.
I'm trying to implement a screen shaking effect. My game uses SDL and is 2D.
My problem is that i'm trying to make the effect by altering the screen's pixels offsets by random ammounts just before the call to SDL_Flip() at the end of each frame. This is ok but when the screen shakes, there will be ugly black spaces around my game scene because nothing was renered there. I hope you understand my problem.
The solution I came up with is, in my opition, pretty complicated and looks unnecessary. What I will do is have the rest of my game draw to a surface that's 32 pixels bigger in each direction. The rendering code will make sure that no important info is drawn in the 32 pixel border. When the frame is about to end, just before the call to SDL_Flip(), The game will do the screen shake effect on the bigger surface and then copy the bigger surface's pixels onto the smaller surface that's the size of the screen. It will make sure to add a 32 pixel offset and not copy pixels that aren't visible on the actual screen. Hopefuly, that wasn't too confusing either... I'm not so good at explaining things.
A small problem that I'm having with this is that I don't know how to set up and free 2 SDL_Surfaces that can be drawn to and updated.
My bigger concern is that there is a very simple way to do this that I don't know about. Should I not bother trying to hack this into my graphics code and put it at a higher level?
Screen Shake Effect
Do you have a scrolling camera? The usual way to do shaking is to just shake the camera. Everything will move accordingly.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement