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.
scene2d is libGDX’s 2D scene graph. At its core, it provides basic 2D scene graph functionality: actors, groups, drawing, events, and actions. This is a lot of utility that applications can leverage, but it is reasonably low level. For games this is fine because most actors are application specific.
Scene2d.ui is mainly designed with touch or mouse control in mind. Stage has a setKeyboardFocus and a setScrollFocus methods to set the Actor receiving scroll and key events. However, it does not support a full type focus and is therefore not operable with keys only.
Widgets can be used as simple actors in scene2d, without using tables or the rest of scene2d.ui. Widgets have a default size and can be positioned absolutely, the same as any actor.
Additionally if you want to use Scene2D for parts of your game ( such as a HUD overlain over your game ) you can. So, what is scene2D?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With