我想在我的方法触摸时返回true,当触摸精灵时(也用手指触摸)我该如何制作?
public class SkipButton extends RectangleButton
{
protected TextureAtlas atlasTexture;
protected Sprite sprite;
protected SpriteBatch batch ;
public SkipButton(Vector2 coordinates, float width, float height)
{
super(coordinates, width, height);
atlasTexture = Assets.manager.get(Constants.INTERFACE_ATLAS_PATH,
TextureAtlas.class);
sprite = new Sprite(atlasTexture.findRegion("skip_big"));
}
@Override
public void draw(SpriteBatch batch)
{
sprite.draw(batch);
}
public boolean touch()
{
...........
}
答案 0 :(得分:0)
Libgdx有一个很棒的Button类,它包含一个boolean isPressed()
,可以做你想要的。如果您希望按钮是私有的,您仍然可以创建一个返回isPressed结果的公共方法。
atlasTexture = Assets.manager.get(Constants.INTERFACE_ATLAS_PATH,
TextureAtlas.class);
Drawable drawable = new TextureRegionDrawable(atlasTexture.findRegion("skip_big"));
button = new Button(drawable);
stage.addActor(button);
public boolean touch() {
return button.isPressed();
}