• 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 Getting information about Collision Mask Type

L

lukbebalduke

Guest
Hey there!

I would like to know if there is a way of getting information about the collision mask type of a given sprite. Either if it is rectangle, diamond, circle etc...

Untitled-1.png

Thanks in advance!
 

O.Stogden

Member
There's sprite_collision_mask which lets you define the mask, including the type and dimensions, but I'm not aware of any function that actually returns what mask type a sprite has.
 
L

lukbebalduke

Guest
There's sprite_collision_mask which lets you define the mask, including the type and dimensions, but I'm not aware of any function that actually returns what mask type a sprite has.
Yeah, I wonder if there is a way of getting those information...
 
I dont see why you would need this information, but you could always create a variable for each instance and manually type in the type of collision mask it has, for example:
Code:
enum MaskType {rectangle, rectRot, ellipse, diamond, precise, precisePerFrame}
maskType = MaskType.ellipse;
shouldn't be that messy to implement.
 
L

lukbebalduke

Guest
I dont see why you would need this information, but you could always create a variable for each instance and manually type in the type of collision mask it has, for example:
Code:
enum MaskType {rectangle, rectRot, ellipse, diamond, precise, precisePerFrame}
maskType = MaskType.ellipse;
shouldn't be that messy to implement.
That would work, but the cohesion of the solution would be a problem. The number of issues would include: changing the mask type in the sprite and forgetting to set in the code; possibly setting the mask type wrong in the code. Besides the fact that every single sprite would need additional work.

Talking about why I would need that, let's say the player gets a super tech google that outlines the collision shape of every object in the game with a blue line. How would I be able to draw the outline showing the collision shape correctly of each object if they have diverse mask types?
 
You could assign each object a sprite as its mask using mask_index, then draw it on top of the object's sprite:
Code:
draw_sprite(mask_index, 0, x, y);
Well, there are many other ways of drawing the mask, but yes i can see how it could be useful as a built-in function for debugging purposes.
Personally I mostly avoid using sprites as their own masks for the same reason that i like to visually see the actual collision mask without going in the sprite editor each time.
 
L

lukbebalduke

Guest
You could assign each object a sprite as its mask using mask_index, then draw it on top of the object's sprite:
Code:
draw_sprite(mask_index, 0, x, y);
Well, there are many other ways of drawing the mask, but yes i can see how it could be useful as a built-in function for debugging purposes.
Personally I mostly avoid using sprites as their own masks for the same reason that i like to visually see the actual collision mask without going in the sprite editor each time.
Again, the mask_index is just another sprite at the end of the day. A sprite that does not actually represent visually its own collision mask can be assigned as mask_index, leading to some inaccurate results.
 
Again, the mask_index is just another sprite at the end of the day. A sprite that does not actually represent visually its own collision mask can be assigned as mask_index, leading to some inaccurate results.
You're right, I forgot to mention that the sprite you use as the mask should look the same as its collision area to avoid confusion.
 
Top