GML [SOLVED] How do I show my collision mask mid-game?

Discussion in 'Programming' started by Dr_Nomz, Jan 12, 2019 at 5:05 AM.

  1. Dr_Nomz

    Dr_Nomz Member

    Joined:
    Oct 31, 2016
    Posts:
    426
    I have a weird bug I don't know how to get rid of because I can't see what's happening, so how do I show my collision mask?

    What my character does is they can roll, and they do this by running "instance_change(obj_Character_Roll,True)", and depending on where the mouse is, that's the direction they roll in. This changes there sprite, sets there speed, and once the animation plays out, they stop and change back to whatever weapon they were holding.

    What happens that's weird is they roll pass a "trigger" and even though they aren't touching it, it gets activated anyway, even though this should be impossible.

    Just figured I should include all that in case it's somehow relevant.
     
  2. Sam04

    Sam04 Member

    Joined:
    Nov 26, 2018
    Posts:
    24
    I assume you are not using pixel precise collision (which is good because using it is a bad idea) so if you are using a separate sprite as the mask then you only need to write:

    Draw Event:
    Code:
    draw_sprite(x,y, name_of_the_mask);
    If you are not using a dedicated mask and using ones you defined in the sprite themselves then you should write this instead:

    Draw Event:
    Code:
    draw_set_colour(c_black);//Or any other color, I choose black on a whim
    draw_rectangle(bbox_left, bbox_top, bbox_right, bbox_bottom, false);
    Just a few things to note in both solutions:
    • In the second one I choose the color black but any color will work. I wrote black because I had to write something in there.
    • You can also put before them a "draw_set_alpha(0.5)" to make the mask semi-transparent so that you can also keep seeing the regular sprite. Which leads me to...
    • Both of these solutions go in the draw event but must always go after the function that draws your regular sprite (that is if you still want to see it). If you don't have one then you can just use "draw_self();".
    • If you collision mask is instead an ellipse, you'll have to replace the draw_rectangle function with the ellipse one.
    • If you instead used the diamond shape (I wouldn't even think why) you'll have to do math and replace the draw_rectangle function with two draw_triangle functions.

    Hope that helps.
     
  3. Dr_Nomz

    Dr_Nomz Member

    Joined:
    Oct 31, 2016
    Posts:
    426
    whoa wtf the box grows twice it's size when rolling diagonally. That sucks... thanks for the help, I think I can fix it now!
     

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