2

私はこのように新しいアクターを定義しました:

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()を呼び出します。アクターが表示されますが、入力に応答しませんコードの何が問題になっていますか?:?:

4

1 に答える 1

5

アクターのSoundsを設定し、コンストラクターに追加する必要があります。

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に設定していることに注意してください

于 2013-02-21T08:53:07.293 に答える