如何创建LibGDX ImageButton

・1 分钟阅读

我刚开始使用libGDX,所以,我不知道创建LibGDX Scene2d ImageButton是否有更好的方法,但是我可以确认:

Texture hikeTexture = new Texture(Gdx.files.internal(\"hike_btn.jpg\"));
Texture hikeTexturePressed = new Texture(Gdx.files.internal(\"hike_btn_pressed.jpg\"));
hikeButton = new ImageButton(
 new TextureRegionDrawable(new TextureRegion(hikeTexture)),
 new TextureRegionDrawable(new TextureRegion(hikeTexturePressed))
);
hikeButton.setPosition(60, 300); //hikeButton is an ImageButton
stage.addActor(hikeButton);

我在实现Screen的类的show()方法中使用此代码,它可以按预期方式工作。

Xn_warm profile image