1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 Wrap around screen when outside view?

Discussion in 'Programming' started by SSJ Silky, Feb 26, 2019.

  1. SSJ Silky

    SSJ Silky Member

    Joined:
    Jan 10, 2019
    Posts:
    5
    I know GM has a built-in function for wrapping an object when outside of the room but I want to know if I can do the same thing when an object leaves a view. Or better yet, when an object reaches a certain x or y coordinate.
     
  2. NeZvers

    NeZvers Member

    Joined:
    Mar 24, 2018
    Posts:
    320
    I'd use draw_sprite_part()
    Or draw a copy of sprite on the other side (preferably draw_sprite_ext) to have the same effect with less mess.
    But object wrap simply:
    Code:
    if(x<view_xview){x+=view_wview;}
    if(x>view_xview+view_wview){x-=view_wview;}
    
    same for y sides
     
    Last edited: Feb 26, 2019
  3. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,642
    Do you want it to go all the way out of the view before wrapping?

    Simply drawing the sprite won't work with collisions, though. Although I do agree, you should draw a copy of the sprite.

    Code:
    if !bbox_left {
        x += view_wview;
        draw_self();
        x -= view_wview; 
    }
    else
    if bbox_right - view_xview - view_wview {
        x -= view_wview;
        draw_self();
        x += view_wview;
    }
    If you use the built-in collision options, then if there's no collision, check if you're outside the view at all and then check for a collision on the opposite side of the view. If you used your own collision detection method, you could probably do something like
    Code:
    bb_right = (bbox_right + view_wview/2) mod view_wview;
    bb_left = (bbox_left + view_wview/2) mod view_wview;
    
    Then you can compare bb_right and bb_left values to test for overlaps.
     
  4. SSJ Silky

    SSJ Silky Member

    Joined:
    Jan 10, 2019
    Posts:
    5
    Thank you both! I did it a little differently but I got it to work
     

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