W
W
wolf-98302015-01-21 20:42:50
Java
wolf-9830, 2015-01-21 20:42:50

How to intercept touch in libgdx?

Hello, how do I know that the user has touched the start button on the screen? (I have it just a rectangle with a texture).
I think like this:
We intercept the coordinates using Gdx.input.isTouched(), and then I build a Rectangle from these coordinates and handle the collusion, but then how do I handle the collision of two Rectangles?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin, 2015-01-22
@KChernenko

A little misunderstood the specifics of the question? Do you want to know how to handle a collision or believe it?
To check for a collision of two Rectangles, the Intersector class has a method called overlaps , which takes two Rectangle objects and returns true if a collision occurs - if I'm not mistaken.
And how to handle this collision is up to you to decide based on the context of the task.
You can for example:

if(Gdx.input.isTouched()) {
     Rectangle r1 = new Rectangle();
     Rectangle r2 = new Rectangle();
     if(Intersector.overlaps(r1, r2)) {
           Gdx.app.log("Game", "Collision");
     }
}

F
fresheed, 2015-01-23
@fresheed

If you already use the library, then why not use the built-in interface tools? There is a scene2d.ui package (most of the information you need is here ). I would not advise writing bicycles - the rake is painfully familiar.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question