Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scene2d how to handle touched actor?(LibGDX)

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.

like image 278
Pawel Avatar asked Sep 28 '13 21:09

Pawel


People also ask

What is scene2d in GDX?

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.

Does scene2d have a full type focus?

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.

What is the use of a widget in scene2d?

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.

Can I use scene2d in my game?

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?


1 Answers

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.

like image 88
Jeremy Scoggins Avatar answered Sep 18 '22 22:09

Jeremy Scoggins