2013-02-21 92 views
2

迴應我定義了新的演員是這樣的:Libgdx演員不輸入

class MyActor extends Image 
{ 
    Texture texMyActor; 

    public MyActor() 
    { 
     super.setTouchable(Touchable.enabled); 
     texMyActor = new Texture("data/myActor.png"); 
     addListener(new InputListener() 
     { 
      public boolean touchDown(InputEvent event, float x, float y, 
        int pointer, int button) 
      { 
       System.out.println("down"); 
       return true; 
      } 

      public void touchUp(InputEvent event, float x, float y, 
        int pointer, int button) 
      { 
       System.out.println("up"); 
      } 
     }); 
    } 

    @Override 
    public void act(float delta) 
    { 
     super.act(delta); 
    } 

    @Override 
    public void draw(SpriteBatch batch, float parentAlpha) 
    { 
     batch.draw(texMyActor, 200, 200); 
    } 
} 

我還添加了演員的階段,登記階段,作爲當前輸入處理器。 然後我調用stage.act(deltaTime)和stage.draw()。 我看到我的演員,但它沒有迴應輸入 我的代碼有什麼問題? :?:

回答

5

你有你的演員的setBounds以及 添加到您的構造函數:

texMyActor = new Texture("data/myActor.png"); 
//setting width and height according to the texture 
setWidth(texMyActor.getWidth()); 
setHeight(texMyActor.getHeight()); 
//setting bound of the actor 
setBounds(200, 200, getWidth(), getHeight()); 

通知我的邊界位置設置爲200,200,因爲你畫有