area(opt?: AreaCompOpt): AreaComp

Attach a collider area from shape and enables collision detection in a Game Object.

paramopt- Options for the area component. See

// Automatically generate area information from the shape of render
const player = add([
    sprite("bean"),
    area(),
])

// Die if player collides with another game obj with tag "tree"
player.onCollide("tree", () => {
    destroy(player)
    go("lose")
})

// Check for collision manually every frame instead of registering an event
player.onUpdate(() => {
    if (player.isColliding(bomb)) {
        score += 1
    }
})

returnsThe area comp.

sincev2000.0

kaplay logo

Misc

Layer