detectMapCollision()
Purpose
Used to detect whether a given sprite has collided with map collision boxes
Description
Receives a sprite handle and returns either true (collided) or false (not collided) if the sprite has collided with a map collision box data.
Syntax
collide = detectMapCollision( sprite )
Arguments
collide Returned Boolean value to indicate collision. Returns true (1) if collided, false (0) if not collided.
sprite Handle of the sprite being checked.
Example
// To view this map demo, please load the project "Map Collision" from FUZE Programs.
// Maps must be stored in the project you wish to load them into.
loadMap( "map1" )
img = loadImage( "Untied Games/Bat and Ball ball" )
plr = [
.spr = createSprite(),
.vel = {},
.col = white
]
setSpriteImage( plr.spr, img )
setSpriteScale( plr.spr, { 1, 1 } )
setSpriteCamera( 0, 0, 2 )
loop
centreSpriteCamera( 0, 0 )
clear()
updateSprites()
c = controls( 0 )
plr.vel += { c.lx, -c.ly } * 80
plr.vel *= 0.87
setSpriteSpeed( plr.spr, plr.vel )
setSpriteColour( plr.spr, plr.col )
drawMapLayer( 0 )
drawMapLayer( 1 )
if detectMapCollision( plr.spr ) then
plr.col = red
else
plr.col = white
endif
drawSprites()
printAt( 0, 0, "Move the ball by using the left control stick" )
printAt( 0, 2, "Ball will appear red when colliding with map collision boxes, white when not colliding" )
update()
repeat
Associated Commands