我已经在 stackoverflow 上阅读了一些答案,试图弄清楚为什么我的 SpriteActor 输入事件在没有任何运气的情况下不会被触发。不知道我做错了什么。如果有人可以提供帮助,我将不胜感激。
- 屏幕类
public class MainGameScreen implements Screen
{
Stage _stage;
public MainGameScreen()
{
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
_stage=new Stage(w,h,true);
Gdx.input.setInputProcessor(_stage);
TextureAtlas atlas = new TextureAtlas(Gdx.files.internal("data/texturesHD.atlas"));
SpriteActor actor= new SpriteActor(atlas,"BtTemple",true);
actor.x=w/2.0f;
actor.y=h/2.0f;
_stage.addActor(actor);
}
public void dispose()
{
}
public void hide()
{
}
public void resize(int width, int height)
{
}
public void resume()
{
}
public void show()
{
}
public void render(float deltaTime)
{
_stage.draw();
}
public void pauseGame()
{
}
// this is called by android
public void pause()
{
}
}
这里是我的 SpriteActor 类:
class SpriteActor extends Actor
{
private Sprite _sprite;
public SpriteActor(TextureAtlas atlas, String regionName, boolean touchable)
{
super();
_sprite = atlas.createSprite(regionName);
//setWidth(_sprite.getWidth());
//setHeight(_sprite.getHeight());
//setBounds(x,y,getWidth(),getHeight());
this.touchable=touchable;
}
@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, x, y);
}
@Override
public Actor hit(float x, float y)
{
return null;
}
@Override
public boolean touchDown (float x, float y, int pointer)
{
Gdx.app.debug("Game", "TestActor.touchDown()");
return true; // must return true for touchUp event to occur
}
@Override
public void touchUp (float x, float y, int pointer)
{
Gdx.app.debug("Game", "TestActor.touchUp()");
}
}
提前致谢。