2011-11-27 61 views

回答

2

您需要爲指針事件添加偵聽器。以下是實現該目的的一種簡單方法:

... 
import playn.core.Pointer; 

public class HitTestGame implements Game 
{ 

    @Override 
    public void init() 
    { 

     ... 

     final HitTestGame self = this; 

     // pointer 
     pointer().setListener(new Pointer.Adapter() { 

      @Override 
      public void onPointerEnd(Pointer.Event event) 
      { 
       self.onPointerUp((int)event.x(), (int)event.y()); 
      } 

      //public void onPointerStart(Pointer.Event event) 
      //public void onPointerDrag(Pointer.Event event) 

     }); 

     ... 

    } 

    public void onPointerUp(int x, int y) 
    { 

     // Do region checks here 
     if ((x >= entity.left() && x <= entity.right()) 
       && (y >= entity.top() && y <= entity.bottom())) 
     { 
      System.out.println("Entity has been clicked!"); 
     } 

    } 

    ... 

} 
相關問題