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 可触摸的最简单方法是什么?


基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01