Skip to main content
GameDev.net gamedev.net
🔒 Locked

Screen Shake Effect

Started by Lith May 26, 2012 at 6:49 AM 2 replies 6.4k views
Original Post
Lith
Lith
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?
Sik_the_hedgehog
Sik_the_hedgehog
Do you have a scrolling camera? The usual way to do shaking is to just shake the camera. Everything will move accordingly.
Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.
Lith
Lith

Do you have a scrolling camera? The usual way to do shaking is to just shake the camera. Everything will move accordingly.


Yeah, I thought of that but I wanted a way to put it in my low level graphics system, I might just do what you said though, it seems much easier and stable.
Lith
Lith
Just thought I would say that I got it to work biggrin.png Thanks!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.