sprite_collision_mask

Defines a collision mask for the given sprite.

Syntax:

sprite_collision_mask(ind, sepmasks, bboxmode, bbleft, bbtop, bbright, bbbottom, kind, tolerance);


Argument Description
ind The index of the sprite to set the bounding box of.
sepmasks Whether to create collision masks for each sub-image of the sprite (true), or one mask for all (false).
bboxmode What kind of bounding box to use. 0=automatic, 1=full image, 2=user defined.
bbleft The maximum left position of the bounding box.
bbtop The maximum top position of the bounding box.
bbright The maximum right position of the bounding box.
bbbottom The maximum bottom position of the bounding box.
kind The kind of mask (0=precise, 1=bounding box, 2=disk, 3=diamond).
tolerance Indicates the tolerance in the transparency value (0=no tolerance, 255=full tolerance).


Returns: N/A


Description

With this function you can set the type of collision mask that a sprite should have. If you select either automatic, or precise, then the bounding box values can be set to 0, however for a user defined mask you will have to set these values.

The bounding box is always a relative value, based on the (0,0) position being the top left corner of the sprite (irrespective of the x and y origin).

The kind of mask sets the general shape for the mask itself, although if you have a user defined bounding box, you may end up with a "cut off" mask that is not complete.

Finally, tolerance is used to define how precise the precise mask is, with a tolerance of 0 meaning that the mask will follow every single pixel that has a transparency over 0, while other values will shift the collision mask perimeter depending on the transparency of the pixels.

NOTE: This function is only useful for bitmap sprites and will not work with SWF or JSON (Spine) sprites.

NOTE: This function will only work on duplicated sprites and not directly on pre-made resources. you can duplicate sprites using the function sprite_duplicate.


Example:

spr = sprite_add("player_5.png", 16, true, true, 0, 0);
sprite_collision_mask(spr, true, 1, 0, 0, 0, 0, 0, 0);

The above code loads a sprite from an external source and stores the new index in the variable "spr". The code then sets the new sprite to have a precise collision mask for each of its sub-images.


Back: Sprites
Next: sprite_set_offset
© Copyright YoYo Games Ltd. 2018 All Rights Reserved