简体   繁体   English

我想在触摸精灵时返回true

[英]I want to return true when my sprite is touched

i want to return true to my method touch, when the sprite is touched (also with the finger) how can I make? 我想对方法触摸返回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()
    {
       ...........
    }

Libgdx has a great Button class which has included a boolean isPressed() which will do what you want. Libgdx有一个很棒的Button类,其中包括一个boolean isPressed() ,它将执行您想要的操作。 You can still make a public method that returns the result of isPressed if you want your button to be private. 如果您希望按钮是私有的,您仍然可以使public方法返回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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM