SOLVED: collision_rectangle - Does it work on child objects?

Discussion in 'Programming' started by DividingByZero, Sep 10, 2019.

  1. DividingByZero

    DividingByZero Member

    Joined:
    Jan 31, 2017
    Posts:
    504
    Quick question - I am trying to use collision_rectangle to detect if an object is within a certain area. It works fine on the parent object (the main object). But, I also have variants of that object that are children, it doesn't seem to detect those (though I feel it should).

    Am I incorrect in my assumption?

    This works with 'obj_torch'
    Code:
    var torch_in_room = collision_rectangle(0,0,2000,2000,obj_torch,true,true);
    if ( torch_in_room == noone ) {
      // Do stuff
    }
    
    But, if I have 'obj_torch_invisible' (which is a child of 'obj_torch') it doesn't work.
     
  2. CloseRange

    CloseRange Member

    Joined:
    Jul 2, 2016
    Posts:
    759
    from the docs on parents:
    you can imagine every bit of code is copied and pasted from one to aother BUT!!!!
    what might be your problem is this

    if your parent has code in the step event and your child also has code in the step event the step event code will NOT be parented.
    if this is the case for you then write this in the child code:
    Code:
    event_inherited();
    event_inherited will inherit any code from the parent object for that specific event
     
    DaMuffin likes this.
  3. DividingByZero

    DividingByZero Member

    Joined:
    Jan 31, 2017
    Posts:
    504
    Sure, that makes sense. In this case, though, I have another object checking for these objects. I was hoping that when I do a collision_rectangle and specify an object, it also applies to it's children. That might not be the case, as it seems.
     
  4. CloseRange

    CloseRange Member

    Joined:
    Jul 2, 2016
    Posts:
    759
    i did a quick test to see and no it should be working.
    collision_rectangle will check the object specified along with all children object, returning the instance as expected.
    The problem has to be somewhere else
     
  5. DividingByZero

    DividingByZero Member

    Joined:
    Jan 31, 2017
    Posts:
    504
    Ok, thanks for confirming, I will keep at it - something else must be goofed up.
     
  6. DividingByZero

    DividingByZero Member

    Joined:
    Jan 31, 2017
    Posts:
    504
    I figured out the issue. The collision_rectangle needs the child object to have a sprite assigned to it. My child object was without a sprite, adding that fixed it.
     

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