Answer the question
In order to leave comments, you need to log in
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
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");
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question