Super Easy Screen Shake
Screen shake effects are really handy for adding juicy effects to your game - here is my simple, easy to use script to make a screen shake effect in your game!
Add the following events:
CREATE
/// @description Set-Up
shakex = 0
shakey = 0
shakeint = 1
shakelen = 1
xs = camera_get_view_x(view_camera[0])
ys = camera_get_view_y(view_camera[0])
STEP
/// @description Shake
if shakelen = 0 then {
shakex = 0
shakey = 0
instance_destroy()}
if shakelen > 0 then {
shakex = -(shakeint/2)+random(shakeint)
shakey = -(shakeint/2)+random(shakeint)
shakelen -= 1 }
camera_set_view_pos(view_camera[0],xs+shakex,ys+shakey)
/// @function sc_Shake(time,intensity);
/// @param {real} time How long to shake
/// @param {real} intensity How much to shake
function sc_Shake(_time,_intensity){
if instance_number(ob_Shake) = 0 then instance_create_depth(0,0,0,ob_Shake)
with (ob_Shake) {
shakelen = _time
shakeint = _intensity }
}
That's it, all set up! Now, whenever you want to add a little screen shake effect, just call the script:
sc_Shake(<TIME>,<INTENSITY>)
SIDE NOTE: This only works if your camera is not following an object - if your camera IS following an object, edit your code to ensure it is not when the ob_Shake object exists
Related Scripts
Browse these game resources from the community
My tower defense EnamyFactory constructer function
With this script you will be able to easily create new enemy types for tower defense games using just one calling object.
Very Simple Particle Effects
Create a very simple particle effect that you can call from just one script!
The Most Simple Movement Code
Very simple collision code.
Why Join a Game Jam
Looking for a new challenge as a game developer? Consider participating in a game jam!