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

GMS 2 [SOLVED] Is there a difference between collision event and collision code in step event?

Discussion in 'Programming' started by MartinK12, Dec 1, 2019.

  1. MartinK12

    MartinK12 Member

    Joined:
    Feb 26, 2017
    Posts:
    38
    Like in the title is there a difference between using collision event or placing my own collision code in the step event?

    I assume that when I put my own collision code in step event it's going to be run every step, but collision event is also running every step, right? So is there a difference between those two? Maybe performance wise?

    Thank You :)
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,121
    As far as I know, the collision event is directly equivalent to putting the following in a step event:

    Code:
    
    if (place_meeting(x, y, object)) {
         ///do stuff
    }
    
    
    If there is a difference it would be minimal. The real difference is control. While I'm a fan of most events, the collision event is one I never use as it is pretty rare that the pure vanilla place_meeting works for what I am doing.
     
    MartinK12 likes this.
  3. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,136
    Biggest difference is the colliding instance is registered in an event.

    Code:
    if (!place_meeting(xprevious, yprevious, other.id)) {
        ///do stuff
    }
    That code will work in a collision event. It will not work within the block proceeding samspade's code since other points back to the calling instance at that point.

    The step event equivalent is
    Code:
    with instance_place(x,y,object)
     with other {
        //code
    }
    
     
    MartinK12 likes this.
  4. MartinK12

    MartinK12 Member

    Joined:
    Feb 26, 2017
    Posts:
    38
    Thank you for explanations :)
     

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