[SOLVED] Dynamic collision mask dimensions

Filkata

Member
Is it possible to set collision mask dimensions through code the way you can manually edit it through the editor?
I am generating objects with variable dimensions and would like to take advantage of the Mouse Enter/Leave events, do I have to handle collision with the mouse manually instead, can you suggest an elegant approach?

Thanks in advance!
 

TheouAegis

Member
sprite_collision_mask() sets the mask dimensions for the sprite, but it needs to be a generated sprite, not one present in the IDE. Furthermore, it affects the sprite resource itself, not the sprite of any particular instance, so all instances using that sprite will have their mask changed. So that probably won't help you any.

When you say objects with variable dimensions, what exactly do you mean? If you're using image_xscale and image_yscale to change dimensions, that modifies the mask directly. If you mean you are using draw_sprite() calls, then in order to use the Mouse events, you'll need to assign a simple sprite_index and then use image_xscale and image_yscale to stretch that sprite to occupy the drawn dimensions.

If you mean something else, you'll need to elaborate.
 

Joe Ellis

Member
You can set the object's sprite(and mask) to a single pixel, use the image_xyscale to make the box size you want, and in the draw event, don't draw the instance's sprite_index, use another variable "sprite" or something, and if you need to scale the sprite use separate scale variables instead of image_xscale\yscale, simply use these for scaling the collision mask
 

NightFrost

Member
I've done that in several projects. Give the instance 1x1 pixel sprite, set the image scale variables appropriately, in Draw event you then draw whatever. Works as expected.
 
Top