Java 当我的精灵被触摸时,我想返回真值

Java 当我的精灵被触摸时,我想返回真值,java,android,libgdx,Java,Android,Libgdx,我想回到我的方法触摸,当精灵被触摸(也用手指)时,我怎么做 public class SkipButton extends RectangleButton { protected TextureAtlas atlasTexture; protected Sprite sprite; protected SpriteBatch batch ; public SkipButton(Vector2 coordinates, float width, f

我想回到我的方法触摸,当精灵被触摸(也用手指)时,我怎么做

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()
    {
       ...........
    }

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();
}

我发现了一个展示scene2d基础知识的好例子。按钮已经有了一个方法哦,是的,这是真的,这可以更加简化。现在编辑它。