What is the simplest way to make Image touchable in libgdx?(在 libgdx 中使 Image 可触摸的最简单方法是什么?)
问题描述
这是我的代码:
@Override
public void resize(int width, int height) {
super.resize(width, height);
stage.clear();
// background image
Image backImage = new Image(backTexture);
backImage.setX(0);
backImage.setY(0);
backImage.setWidth(800);
backImage.setHeight(480);
// start game image
Image startImage = new Image(startTexture);
startImage.setX(415);
startImage.setY(180);
startImage.setWidth(323);
startImage.setHeight(69);
stage.addActor(backImage);
stage.addActor(startImage);
}
我正在创建简单的游戏,这就是我创建主菜单的方式.我想让我的 startImage 可触摸(可点击),因为 Image 类没有可用的侦听器.我该怎么做?还是使用 ImageButton 更好?这样我就必须创建图像图集,这对我来说似乎有点复杂..
I'm creating simple game and this is the way I'm creating main menu. I want to make my startImage touchable (clickable) as there is no available listener for Image class. How should I do this? Or is it better to use ImageButton? This way I would have to create image atlas which seems to be a little bit complicated for me now..
我尝试了以下操作:
startImage.addListener(new ClickListener() {
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
{
game.setScreen(new SplashScreen(game));
return true;
}
});
但是还是不行..
Gdx.input.setInputProcessor(stage);
需要调用.解决了.
needs to be called. Solved.
推荐答案
解决方案是调用如下:
Gdx.input.setInputProcessor(stage);
这篇关于在 libgdx 中使 Image 可触摸的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 libgdx 中使 Image 可触摸的最简单方法是什么?


- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01