• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

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

Dr_Nomz

Member
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.
 

Sam04

Member
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.
 

Dr_Nomz

Member
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!
 
Top