stadium / Exports / DetectLineCrossing
Class: DetectLineCrossing 
스프라이트가 SensorLine을 지나는지 검사하는 Hook입니다.
검사할 라인의 태그를 지정할 수 있고, 지정되지 않는다면 랜덤한 태그가 생성됩니다.
js
const line = new SensorLine({ ... })
line.tags.push('detect_line') 
const sprite = new ImageSprite({ ... })
const animate = new Animate()
const detector = new DetectLineCrossing({ 
    targetTag: ['detect_line'] 
}) 
detector.pubsub.sub("crossed", () => console.log("라인을 지났습니다!")) 
sprite.use([ detector, animate ]) 
animate.moveTo(100, 0)다음은 targetTag를 지정하지 않고 사용하는 예시입니다.
ts
const detector = new DetectLineCrossing() 
const animate = new Animate()
sprite.use([
  detector, 
  animate
])
const line = new SensorLine({ ... })
line.tags.push(detector.targetTag)  
detector.pubsub.sub("crossed", () => console.log("라인을 지났습니다!")) 
animate.moveTo(100, 0)Hierarchy 
- ↳ - DetectLineCrossing
Table of contents 
Constructors 
Properties 
Methods 
Constructors 
constructor 
• new DetectLineCrossing(behavior?, targetTag?): DetectLineCrossing
DetectLineCrossing 클래스의 인스턴스를 생성합니다.
Parameters 
| Name | Type | Description | 
|---|---|---|
| behavior | Object | - | 
| behavior.blockMove? | boolean | Animate의 이동 경로에 SensorLine이 있을 때, 이동할 수 없도록 합니다. | 
| behavior.clearMovePathAfterBlocking? | boolean | Animate가 DetectLineCrossing에 의해 가로막혔을 때, 나머지 이동 대기열을 비웁니다. | 
| targetTag | string | - | 
Returns 
Overrides 
Hook.constructor
Defined in 
lib/hook/detectLineCrossing.ts:74
Properties 
pubsub 
• pubsub: PubSub<{ blocked: (from: Point, to: Point) => void ; crossed: (from: Point, to: Point) => void }>
crossed, blocked 이벤트를 생성하는 PubSub 인스턴스입니다.
- 스프라이트가 target으로 이동할 때SensorLine을 지나치게 되면crossed이벤트를 생성합니다.
- 만일 behavior.blockMove가true여서 이동이 가로막혔다면blocked이벤트를 생성합니다.
ts
detector.pubsub.sub("crossed", (from: Point, to: Point) => {
    console.log(from, "에서", to, "로 이동하며 라인을 지났습니다.");
});
detector.pubsub.sub("blocked", (from: Point, to: Point) => {
    console.log(from, "에서", to, "로 이동하려 했으나 라인에 막혔습니다.");
});Defined in 
lib/hook/detectLineCrossing.ts:63
Methods 
isCrossing 
▸ isCrossing(target): boolean
스프라이트가 target으로 이동할 때 SensorLine을 지나치는지 검사합니다.
Parameters 
| Name | Type | Description | 
|---|---|---|
| target | Point | 이동할 목적지 | 
Returns 
boolean
target으로 이동할 때 SensorLine을 지나친다면 true를 반환합니다.
ts
const detector = new DetectLineCrossing({});
const sprite = new ImageSprite(...);
sprite.use([detector]);
const line = new SensorLine({ p1: { left: 0, top: 0 }, p2: { left: 100, top: 100 } })
line.tags.push(detector.targetTag);
detector.isCrossing({ left: 50, top: 50 }); // true