java – Libgdx InputListener“exit()”未使用TextButton调用
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – Libgdx InputListener“exit()”未使用TextButton调用,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1548字,纯文字阅读大概需要3分钟。
内容图文
我想在InputListener中使用exit()方法来查看光标是否在按钮内.
以下是libGDX文档中的解释.
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor)
Called any time the mouse cursor or a finger touch is moved out of an actor.
但是当我将光标放在按钮上然后将其移到按钮外时,不会调用该方法.我正在通过System.out.println(“退出”)测试它;我在控制台里什么都没得到.
编辑:
LibGDX版本:最新的稳定夜莺
InputListener实现:
//This button class is a custom class to make button creation easier. This is the constructor.
public Button(Vector2 position, String packLocation, String text, Stage stage, BitmapFont font, Color color) {
//Removed buttonStyle creation etc. to shorten the code.
button = new TextButton(text, buttonStyle);
button.setPosition(position.x, position.y);
stage.addActor(button);
Gdx.input.setInputProcessor(stage);
pressed = false;
button.addListener(new ClickListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
pressed = true;
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
pressed = false;
}
@Override
public void exit(InputEvent event, float x, float y, int pointer, Actor toActor) {
System.out.println("exited");
}
});
}
编辑:
将鼠标悬停在按钮上也不会改变按钮的纹理,因为我将其设置为如此:
buttonStyle.over = skin.getDrawable(“over”);
但点击确实.
解决方法:
搜索了几个小时后,我终于找到了遗漏的东西. stage.act();必须在render方法中调用.当我们将鼠标悬停在按钮上以及InputListener中的enter / exit方法时,这两者都为纹理更改提供了功能.
内容总结
以上是互联网集市为您收集整理的java – Libgdx InputListener“exit()”未使用TextButton调用全部内容,希望文章能够帮你解决java – Libgdx InputListener“exit()”未使用TextButton调用所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。