overlaps With

Check if this sprite is overlapping another sprite.

mySpriteotherSpriteoverlaps with
JavaScript
(method) Sprite.overlapsWith(other: Sprite): boolean;
Python
(method) Sprite.overlaps_with(other: Sprite): bool

An overlap of two sprites is dectected when the first non-transparent pixel in the image of the first sprite overlaps the first non-transparent pixel of the second sprite. If a sprite has it’s ghost flag set, any overlap with another sprite won’t be noticed. Also, an overlap occurs even when the values of Z for the sprites are different.

Parameters

  • other: the other sprite to check for overlap with this sprite.

Returns

  • a boolean value which is true if the other sprite is overlapping this sprite.

Example

Send a blue square toward a red square. While the red square is overlapping the blue square, randomly change the color of the “red” square to something else.

100redBoxStayblueBoxStayoverlaps withredBox115pick randomtofillwithifthenon game update everyms3232create image widthheightblueBox3232create image widthheightredBoxblueBoxspriteof kindredBoxspriteof kindblueBoxStay0blueBoxStay10setvx (velocity x)tosetxtosetredBoxStaytosetblueBoxStaytofillwithsetredBoxtofillwithsetblueBoxtoon start

See also

on overlap