2012-09-19 7 views
13

libgdxのActorで動作するイベントを取得するのに苦労しています。私は夜間のビルドを使用しています。私のlibgdxで動作するイベントを取得できません。Actor

マイステージがScreenサブクラスのshow()方法でセットアップです:

stage = new Stage(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), true); 
Gdx.input.setInputProcessor(stage); 
TestActor actor = new TestActor(); 
stage.addActor(actor); 

そして、私の俳優のクラスは次のようになります。

class TestActor extends Actor { 
    private Sprite sprite; 
    private TextureAtlas atlas; 

    public TestActor() { 
     atlas = new TextureAtlas(Gdx.files.internal("textures/images-packed.atlas")); 
     sprite = atlas.createSprite("logo-96"); 

     setTouchable(Touchable.enabled); 
     addListener(new InputListener() { 
      public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { 
       Gdx.app.debug(TestGame.TAG, "TestActor.touchDown()"); 
       return true; // must return true for touchUp event to occur 
      } 
      public void touchUp (InputEvent event, float x, float y, int pointer, int button) { 
       Gdx.app.debug(TestGame.TAG, "TestActor.touchUp()"); 
      } 
     }); 
    } 

    @Override 
    public void draw(SpriteBatch batch, float parentAlpha) { 
     Color color = getColor(); 
     batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); 
     batch.draw(sprite, getX(), getY()); 
    }    
} 

イベントが起動していないようです。奇妙なことに、私はTextButtonのような組み込みのUIウィジェットを使用しています。誰か私が間違っているのを見ることができますか?

答えて

16

また、あなたの俳優にsetBoundsを設定する必要があります。 (あなたがあなたのテクスチャと同じサイズにしたい場合は)それを行うには 最良の方法 あなたのコンストラクタに次の行を追加します。あなたはまた、最初の2つのパラメータを持つ境界の位置を設定することができ

setWidth(sprite.getWidth()); 
setHeight(sprite.getHeight()); 
setBounds(0, 0, getWidth(), getHeight()); 

予告。

+0

はい!ありがとうございました!私はそれに沿って何かがあるかどうか疑問に思っていました。 –

関連する問題