2014-04-16 6 views
1

저는 님의 일부입니다. EaselJS. 나는 다른 용기에 한 방울의 용기를 어떻게 감지 할 수 있는지 궁금합니다. EaselJS. 그래서 드롭 된 컨테이너의 eventlistener에 컨테이너를 가져 오려고합니다. 이것에 대한 예제가 있습니까? 끌어서 놓기 예제에서 찾을 수 없습니다 EaselJS.easeljs에서 방울 감지

덕분에 pressmove 또는 stagemouseup 이벤트에서

답변

1

, 당신은 확인할 수있는 경우 마우스의 위치 (stage.mouseX 및 stage.mouseY) 부모 컨테이너 이상의 경우. 확인을 수행하려면 hitTest를 사용할 수 있습니다.

공지 사항, 즉 그러나 hitTest 것이다 당신의 부모 컨테이너 내가 EaselJS 0.7.1

2

또한 getObjectsUnderPoint을 사용할 수 있습니다에 버그라고 생각 적어도 하나의 마우스 이벤트의 청취자를 가지고있는 경우에만. 다음은 함께 작성한 간단한 샘플입니다. http://jsfiddle.net/lannymcnie/6rh7P/1/

var targets = stage.getObjectsUnderPoint(stage.mouseX, stage.mouseY);

이 비슷한 질문을 다른 게시물에서입니다 . 나는 또한 그것에 대해 더 많은 정보를 올렸다.

class DragContainer 
    DragContainer.prototype = new createjs.Container() 
    DragContainer::Container_initialize = DragContainer::initialize 
    constructor: (opts) -> 
     @initialize opts 
    DragContainer::initialize = (opts) -> 
     @Container_initialize() 
     @droptargets = new Array() 
     @on 'mousedown', @handleMouseDown 
    handleMouseDown: (e) => 
     @on 'pressup', (ev)=> 
      @removeAllEventListeners 'pressup' 
      if @droptargets and @droptargets.length > 0 
       @evaluateDrop e 
    evaluateDrop: (e) => 
     target = null 
     dropped = false 
     for drop in @droptargets 
      pt = drop.globalToLocal stage.mouseX, stage.mouseY 
      if drop.hitTest pt.x, pt.y 
       target = drop 
       dropped = true 
     if dropped 
      @dispatchEvent {type: 'dropped', currentTarget: target} 
     else 
      @dispatchEvent {type: 'dropped', currentTarget: null} 

드래그 소스 속성은 컨테이너의 드롭과 연결할 개체를 유지하는 배열입니다 : EaselJS: connect 2 containers/shapes using a line

+0

음 ...이 바이올린은 모양을 사용합니다. 컨테이너를 사용하면 작동하지 않습니다. 컨테이너가 getObjectsUnderPoint에 의해 감지되지 않는 것처럼 보입니다 – mvermand

+0

너무 늦게 바이올린을 추가하십시오. http://jsfiddle.net/vHg6L/ 파란색 컨테이너의 빨간색 컨테이너를 드래그하십시오. getObjectsUnderPoint가 빈 배열을 반환합니다. – mvermand

0

는 그 문제를 해결하기 위해 커피 스크립트에이 클래스를했다.