Sign in to follow this  

Screen Shake Effect

This topic is 2062 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
[quote name='Sik_the_hedgehog' timestamp='1338020589' post='4943426']
Do you have a scrolling camera? The usual way to do shaking is to just shake the camera. Everything will move accordingly.
[/quote]

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.

Share this post


Link to post
Share on other sites
Just thought I would say that I got it to work [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] Thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this