简体   繁体   中英

Libgdx swipe gesture across actor

How can I detect a swipe gesture across an actor, started outside the actor's boundary

The action would be as follows 1. User touched the screen outside of the actor boundary 2. The user's finger moves across the screen and enters the actor boundary 3. The actor is then dragged by the user's finger 4. The actor is released once the user lifts their finger

I am able to drag an actor using the dragListener and drag method on the actor. This only works for me if the user touches down inside the actors boundary and then moves their finger to drag the actor.

I would like the user to be able to touch down outside the actor's boundary and then enter and drag the actor

Thanks for your help, I will continue to investigate and post if I find the anwser

You should implement a function which does the following in order:

  • STEP1: Go to STEP2 if Gdx.input.justTouched() method returns true, otherwise repeat

  • STEP2: Go to STEP3 if yourActor.hit(Gdx.input.getX(),
    Gdx.input.getY(), true) return true, otherwise repeat

  • STEP3: Subject Gdx.input.getDeltaX() and Gdx.input.getDeltaY() to
    yourActor and go to STEP4

  • STEP4: Go to STEP3 if Gdx.input.isTouched() is true, otherwise go to STEP1

The main logic is something similar to this, you should be able to get the idea and find yourself a way to implement it in somewhere in your main game loop. Also, if you are not familiar with the functions available in the Input and Actor classes, you should have a look at the API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM