Jump to content

  • Log In with Google      Sign In   
  • Create Account


Screen Shake Effect


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Lith   Members   -  Reputation: 380

Like
0Likes
Like

Posted 26 May 2012 - 12:49 AM

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?

Sponsor:

#2 Sik_the_hedgehog   Crossbones+   -  Reputation: 1608

Like
0Likes
Like

Posted 26 May 2012 - 02:23 AM

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.

#3 Lith   Members   -  Reputation: 380

Like
0Likes
Like

Posted 26 May 2012 - 03:04 AM

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.

#4 Lith   Members   -  Reputation: 380

Like
0Likes
Like

Posted 26 May 2012 - 08:38 AM

Just thought I would say that I got it to work Posted Image Thanks!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS