collideMap()

Purpose

Used to cause sprites to interact with map collision box data.

Description

Receives a sprite handle and returns an array of structures detailing collision data.

Syntax

c = collideMap( sprite )

Arguments

sprite Handle of the sprite being collided

c[i].exists Boolean value (true or false) to indicate whether a collision has occured

c[i].a Handle of the sprite being collided

c[i].resolution_a Vector representing how the supplied sprite must pushed to resolve the collision

c[i].resolution_b Vector representing how the supplied sprite is pushing during the collision

Example

// To view this map demo, please load the project "collideMap() Demo" from FUZE Programs.
// Maps must be stored in the project you wish to load them into.

img = loadImage( "Untied Games/Bat and Ball ball" )

plr = [
    .spr = createSprite(),
    .vel = {}
]

setSpriteImage( plr.spr, img )
setSpriteScale( plr.spr, { 1, 1 } )

loadMap( "map1" )

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 )

    drawMapLayer( 0 )
    drawMapLayer( 1 )

    collision = collideMap( plr.spr )

    drawSprites()

    printAt( 0, 0, "Move the ball using the left control stick" )
    printAt( 0, 2, "Collision exists: " )
    printAt( 0, 4, "Collision Resolution Vector: " )

    if len( collision ) > 0 then
        printAt( 30, 2, collision[0].exists )
        printAt( 30, 4, collision[0].resolution_a )
    endif

    update()
repeat

Associated Commands

drawMap(), drawMapLayer(), getMapArea(), getMapAreaNames(), getMapLocation(), getMapLocationNames(), loadMap(), unloadMap(), updateMap()