0
\$\begingroup\$

I am using "Gdx.input.isTouched()" in the render method of my Screen method, to know where is touched, but when the touch is dragged in the screen, it also activates the events i want only when an actor is touched.

Is there any listener to know when an Actor is touched, but the event is not the dragged one, im doing it with sprites.

\$\endgroup\$
1
\$\begingroup\$

There's a TouchUp and TouchDown method if I'm not mistaken. You need to keep track of state.

I handle this in my projects by creating a custom MyAwesomeSprite class; on TouchDown, I just set _isTouched=true, and on TouchUp, I set _isTouched = false. This allows me to detect dragging (touch-down triggered when _isTouched is already true), so I can easily distinguish between these two cases.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ The touchDown and touchMethod is for the Screen(Stage) right? \$\endgroup\$ – Rudy_TM Feb 11 '12 at 4:33
  • \$\begingroup\$ Not sure. I get mine from the Game class, which implements ApplicationListener and InputProcessor \$\endgroup\$ – ashes999 Mar 12 '12 at 3:30
1
\$\begingroup\$

Add a Listener to the actor like so. Note you need an InputMultiplexer so your Stage and Screen can both handle touches. Add the Stage first so it gets clicks first, then in the Listener call event.handle() and return true otherwise the touch will bubble through and be picked up by your Screen too.

actor.addListener(new ClickListener(){
            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                doSomething(x,y,pointer);
                event.handle();//the Stage will stop trying to handle this event
                return true; //the inputmultiplexer will stop trying to handle this touch
            }
        });

Some actors will require

Actor.setTouchable(Touchable.enabled);
| improve this answer | |
\$\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.