2013-02-21 95 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,因为你画有