Function

patrol

(opts: PatrolCompOpt): PatrolComp

A patrol which can follow waypoints to a goal.

param opts- Options for the patrol component. See

const bean = add([
    sprite("bean"),
    pos(40, 30),
    patrol({
        waypoints: [
            vec2(100, 100),
            vec2(120, 170),
            vec2(50, 50),
            vec2(300, 100),
        ],
    }),
]);

bean.onPatrolFinished(gb => {
    // Note that the position doesn't exactly match the last waypoint,
    // this is an approximation.
    debug.log(`Bean reached the end of the patrol at ${gb.pos.x}, ${gb.pos.y}`);
});

returns The patrol comp.

since v3001.0

group Components

kaplay logo

Layer

Miscalenous