1
\$\begingroup\$

i'm making a game in libgdx and i have a question.

I have a Button from scene2d. If there is a touchDown event on this button, i want the touchUp event only inside my button.

Now if i touchDown a button, then swipe outside my button, libgdx consider this like a touchUp.

I know that i can extend stage and work with it, the question is if there is a simple way to do this...

\$\endgroup\$
0
\$\begingroup\$

Implement one of these and override the methods you need to detect a move outside of your button. You can then disable the normal "touch up" functionality and re-enable it on the "touch up".

https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/utils/DragListener.html

\$\endgroup\$
1
  • \$\begingroup\$ thanks but your solution is the same of extending stage (to have touchUp of the viewport and not of the button)... \$\endgroup\$
    – flagDiZero
    Oct 6 '15 at 6:22
0
\$\begingroup\$

the correct way to achieve this is very simple. touchDown() touchUp() and touchDragged() methods of Button class gives you button relative coordinates (0,0 is the origin of the button) so you can easly check it in touchUp() method:

method of Button class:

 public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
            if(x<0 || y<0 ||x>getWidth() || y>getHeight()){  // means outside the button
                System.out.println("click canceled");

            }else{
                System.out.println("clicked");

        }
    });
\$\endgroup\$
0
\$\begingroup\$

Attach clickListener to the button actor and Just use

Event.handled()

For example

TouchUp(Event event,.......) {

If(event.handled) //do something 

Else //do something 

You have to extend the clickListener class

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.