← View other scripts
script
Super Easy Screen Shake
A little screen-shake effect can make all the difference, here's a super easy way to add one to your game!
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!
1
Make the Control Object
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)
2
Make the Script
/// @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 }
}
3
Enable the Camera
Get Shakin!
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