Screen Shake with views

N

ndaoud360

Guest
I have looked everywhere and none seem to work. How can I get the screen to shake when I press for example "space" My view is following the character which is why none of the ones I found work.
 

jo-thijs

Member
Either you make the view manually follow the character using this in the end step event:
Code:
view_xview = clamp(x - (view_wview div 2), 0, room_width - view_wview);
view_yview = clamp(y - (view_hview div 2), 0, room_height - view_hview);
and apply the shake code afterwards.

Or you apply the shake effect in the begin draw event (if multiple views are used, this can have a different effect).
 
N

ndaoud360

Guest
Either you make the view manually follow the character using this in the end step event:
Code:
view_xview = clamp(x - (view_wview div 2), 0, room_width - view_wview);
view_yview = clamp(y - (view_hview div 2), 0, room_height - view_hview);
and apply the shake code afterwards.

Or you apply the shake effect in the begin draw event (if multiple views are used, this can have a different effect).
I just tried manually following the character and still didn't work.
 

RangerX

Member
I think a nice way to have camera shake and other nice effect like panning, easy "real time cut-scene" and such stuff is to have camera object. And then you make your view follow the cam, not the player.
With that cam you can have alot of fun, you make it follow the player, you change its X and Y position with a random and create screen shake, etc.
 
N

ndaoud360

Guest
I think a nice way to have camera shake and other nice effect like panning, easy "real time cut-scene" and such stuff is to have camera object. And then you make your view follow the cam, not the player.
With that cam you can have alot of fun, you make it follow the player, you change its X and Y position with a random and create screen shake, etc.
Yea I tried something similar and while it worked, whenever the player is following the view the shake wont happen.

I did forget to mention though, that my view intentionally rotates when I rotate the player left or right f that effects anything.
 

RangerX

Member
Anyhow it entirely depends on your code. If it didn't work its not because it wasn't a good way to do it, its because there's something wrong about your code or stuff you didn't think through.
If you want to go more in-depth, I'd invite you to share people your related code.
 
N

ndaoud360

Guest
Anyhow it entirely depends on your code. If it didn't work its not because it wasn't a good way to do it, its because there's something wrong about your code or stuff you didn't think through.
If you want to go more in-depth, I'd invite you to share people your related code.
Here is my screen shake code.

create:
Code:
shakeIntensity = 0;
step event:
Code:
if (shakeIntensity > 0)
{
    view_xview[0] += choose(random(shakeIntensity), random(-shakeIntensity));
    view_yview[0] += choose(random(shakeIntensity), random(-shakeIntensity));
}
Alarm[1]:
Code:
shakeIntensity -= 10;
alarm[1] = 0.2 * room_speed;
Keyboard pressed space:
Code:
shakeIntensity = 10;
alarm[1] = 0.2 * room_speed;
This code does work as long as my player is not being followed.
 

NicoDT

Member
Hi! I used to have the same problem as you, and found a solution.
In obj_shake:

Create event
Code:
view_visible[1]=1;
Step event
Code:
view_xview[1]=view_xview[0]+(irandom(amount)-amount/2);
view_yview[1]=view_yview[0]+(irandom(amount)-amount/2);
Destroy event
Code:
view_visible[1]=0;
View[1] should not follow the player, and have same size as View[0]

I later created an obj_camera to follow the player, so I stopped using this method (should've done it from the start...)
 
N

ndaoud360

Guest
Hi! I used to have the same problem as you, and found a solution.
In obj_shake:

Create event
Code:
view_visible[1]=1;
Step event
Code:
view_xview[1]=view_xview[0]+(irandom(amount)-amount/2);
view_yview[1]=view_yview[0]+(irandom(amount)-amount/2);
Destroy event
Code:
view_visible[1]=0;
View[1] should not follow the player, and have same size as View[0]

I later created an obj_camera to follow the player, so I stopped using this method (should've done it from the start...)
Thanks this actually worked but the shaking doesn't stop. Should I create an alarm to make it stop?

EDIT: Used an alarm and it worked.
 
Last edited by a moderator:
X

xxDOOMbox

Guest
Hi! I used to have the same problem as you, and found a solution.
In obj_shake:

Create event
Code:
view_visible[1]=1;
Step event
Code:
view_xview[1]=view_xview[0]+(irandom(amount)-amount/2);
view_yview[1]=view_yview[0]+(irandom(amount)-amount/2);
Destroy event
Code:
view_visible[1]=0;
View[1] should not follow the player, and have same size as View[0]

I later created an obj_camera to follow the player, so I stopped using this method (should've done it from the start...)
thank you!!! i had the same problem and implemented a solution similar to yours. it was quite frustrating for awhile, so thank you for your help!
 
J

JeGaboii

Guest
I have looked everywhere and none seem to work. How can I get the screen to shake when I press for example "space" My view is following the character which is why none of the ones I found work.
Easiest Screenshake EVER!!!!

Just make a o_camera object and make it as the view.

o_camera Create Event:
Code:
/// Camera Target
target_ = o_player; // Camera target, (What camera will be following)

/// Screen Shake Amount
min_amount_ = 1; // Min Screen Shake
max_amount_ = 10; // Max Screen Shake

/// Screen Shake On or Off
screen_shake_ = false; // Screen Shake On or Off?

o_camera Step Event
Code:
/// If Screen Shake is True, DO SCREEN SHAKE
if (screen_shake_ == true)  {
    x = target_.x+random_range(min_amount_, max_amount_)
    y = target_.y+random_range(min_amount_, max_amount_)
}



HOW EASY IS THAT?
 

jobjorgos

Member
Thanks jeGaboii that works pretty good!!

But there is just a small problem for me.
I have a room of 1024/768 with 3 views that follows the player, view0 = 1024/768, view1 = 768/576, view2 = 512/384.

And only the camera of view2 shakes. in view 0 and 1 it doesnot shake at all, even not when my view is not touching the edges of the room.

Anything I can change so it works also for view0 (1024/768) and view1 (768/576)?
 

jobjorgos

Member
ah i discovered that it is important that
A: the view does not touch the edges of the room
B: at the view settings below following object: having Hbor and Vbor, Hsp and Vsp all on a high amount, 8000 for example
C: dont forget to set in the view to follow the camera and not the player!
 
Top