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
↳
Nearness
Table of contents
Constructors
Constructors
constructor
• new Nearness(props
): Nearness
ts
new Nearness({
targetTags: ["enemy"],
distance: 20,
handler: onNearEnemy,
});
Parameters
Name | Type |
---|---|
props | Object |
props.distance? | number |
props.handler | (...args : [Sprite , Sprite ]) => unknown |
props.targetTags | string [] |
Returns
Overrides
Hook.constructor