Skip to content

stadium / Exports / Nearness

Class: Nearness

Nearness는 Sprite와 다른 Sprite 사이 거리의 근접을 감지하는 Hook입니다.

ts
const me = new ImageSprite(...);

const enemy1 = new ImageSprite(...);
const enemy2 = new ImageSprite(...);

enemy1.tags.push("enemy");
enemy2.tags.push("enemy");

me.use([
    new Nearness({
        targetTags: ["enemy"],
        distance: 20,
        handler: onNearEnemy,
    }),
]);

function onNearEnemy(me: Sprite, enemy: Sprite) {
    console.log("Near enemy!");
}

Hierarchy

Table of contents

Constructors

Constructors

constructor

new Nearness(props): Nearness

ts
new Nearness({
   targetTags: ["enemy"],
   distance: 20,
   handler: onNearEnemy,
});

Parameters

NameType
propsObject
props.distance?number
props.handler(...args: [Sprite, Sprite]) => unknown
props.targetTagsstring[]

Returns

Nearness

Overrides

Hook.constructor

Defined in

lib/hook/nearness.ts:57