Scene2d如何处理被触摸的演员?(LibGDX) [英] Scene2d how to handle touched actor?(LibGDX)

查看:81
本文介绍了Scene2d如何处理被触摸的演员?(LibGDX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在libgdx中使用scene2d时遇到问题.我在任何地方都找不到可以让我检查演员是否被触碰的方法.我只能找到告诉我演员是否被触摸或释放的方法.在我的游戏中,当按住演员的时候,应该在每一帧中都要做一些事情,而不仅仅是在我用手指指着它的那一刻.我想放开手指就停下来.

I have a problem with using scene2d in libgdx. I can't find anywhere a method that allows me to check wheter the actor is touched or not. I can only find methods that told me if actor was touched or released. In my game, when actor is pressed and hold, some things should be done every frame, not only in one moment that I put my finger on it. I want to stop the things when I release my finger.

推荐答案

您可以在InputListener中进行跟踪.创建一个布尔字段isTouched,当您获得touchDown时将其设置为true,而当您获得touchUp时将其设置为false.我在自上而下的射击游戏中使用了这种方法,效果很好.

You can keep track of this in your InputListener. Create a boolean field isTouched, set to true when you get a touchDown, false when you get a touchUp. I use this method in my top-down shooter and it works very well.

这篇关于Scene2d如何处理被触摸的演员?(LibGDX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆