Button 有人能告诉我如何在libgdx中制作按钮吗

Button 有人能告诉我如何在libgdx中制作按钮吗,button,mobile,libgdx,touch,Button,Mobile,Libgdx,Touch,嗨,有人能告诉我如何制作一个可点击的按钮吗​在Libgdx中 对于一个移动设备来说,如果你触摸它,它会做一些事情,这是你试图通过评论来实现的一个最小的例子 package com.mygdx.gtest; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.scenes.sce

嗨,有人能告诉我如何制作一个可点击的按钮吗​在Libgdx中
对于一个移动设备来说,如果你触摸它,它会做一些事情,这是你试图通过评论来实现的一个最小的例子

package com.mygdx.gtest;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;

public class Test extends ApplicationAdapter{


    private Skin skin;
    private TextButton button;
    private Stage stage;

    @Override
    public void create() {
        //make a stage for your button to go on
        stage = new Stage();

        //load a skin(a collection of styles for objects)
        // skin is from gdx-skins (https://github.com/czyzby/gdx-skins)
        skin = new Skin(Gdx.files.internal("neon-ui.json"));

        //create your button
        button = new TextButton("Button1", skin);

        //add it to your stage
        stage.addActor(button);

        // add a listener to your buttons so it does something when clicked
        button.addListener(new ChangeListener() {
            @Override
            public void changed(ChangeEvent event, Actor actor) {
                System.out.println("I was clicked");
            }
        });

        // set the sgae as the input processor so it will respond to clicks etc
        Gdx.input.setInputProcessor(stage);

    }

    @Override
    public void render() {
        //clear the screen
        Gdx.gl.glClearColor(0.3f, 0.3f, 0.3f, 1f);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        // tell stage to do action and then draw itself
        stage.draw();
        stage.act();
    }
}

这就是如何在不添加任何外部蒙皮的情况下添加按钮

TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
textButtonStyle.font = yourCustomFont;
textButtonStyle.fontColor = Color.WHITE;
stage.add(new TextButton("Custom Btn ", textButtonStyle));

可能会有帮助Nop不能真的说它是
对于一个移动设备来说,如果你触摸它,它会做一些事情吗
?如果你触摸一个纹理/精灵,它会做一些事情吗?所以你希望有人提供代码吗?这看起来不错,但我现在没有时间去做。我会尽快让你知道的。不要做我想做的事。什么不管用?它可以很好地在我打印出“我被点击”时点击