1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

Screen Shake with views

Discussion in 'Programming' started by ndaoud360, Sep 4, 2016.

  1. ndaoud360

    ndaoud360 Member

    Joined:
    Jul 9, 2016
    Posts:
    65
    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.
     
  2. jo-thijs

    jo-thijs Member

    Joined:
    Jun 20, 2016
    Posts:
    2,844
    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).
     
    deva56 likes this.
  3. ndaoud360

    ndaoud360 Member

    Joined:
    Jul 9, 2016
    Posts:
    65
    I just tried manually following the character and still didn't work.
     
  4. RangerX

    RangerX Member

    Joined:
    Jun 20, 2016
    Posts:
    2,602
    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.
     
  5. ndaoud360

    ndaoud360 Member

    Joined:
    Jul 9, 2016
    Posts:
    65
    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.
     
  6. RangerX

    RangerX Member

    Joined:
    Jun 20, 2016
    Posts:
    2,602
    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.
     
  7. ndaoud360

    ndaoud360 Member

    Joined:
    Jul 9, 2016
    Posts:
    65
    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.
     
  8. NicoDT

    NicoDT Member

    Joined:
    Jun 21, 2016
    Posts:
    237
    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...)
     
    xxDOOMbox likes this.
  9. ndaoud360

    ndaoud360 Member

    Joined:
    Jul 9, 2016
    Posts:
    65
    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: Sep 4, 2016
  10. xxDOOMbox

    xxDOOMbox Guest

    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!
     
    NicoDT likes this.
  11. JeGaboii

    JeGaboii Guest

    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 likes this.
  12. jobjorgos

    jobjorgos Member

    Joined:
    Jun 23, 2016
    Posts:
    153
    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)?
     
  13. jobjorgos

    jobjorgos Member

    Joined:
    Jun 23, 2016
    Posts:
    153
    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!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice