Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>public static boolean pointInRectangle (Rectangle r, float x, float y) { return r.x &lt;= x &amp;&amp; r.x + r.width &gt;= x &amp;&amp; r.y &lt;= y &amp;&amp; r.y + r.height &gt;= y; } </code></pre> <p>In your update-</p> <pre><code>if(pointInRectangle(flyRectangle, Gdx.input.getX(), Gdx.input.getY())){ // Do whatever you want to do with the rectangle. maybe register them for effect } </code></pre> <p>You can also look into <a href="http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/math/Intersector.html" rel="nofollow">Intersector</a> class.</p> <p>Now for collision, if your game is fast-paced, with lots of enemies moving around that the player can collide with, sooner or later you will use a box2d type library because if the movement speed is high, you might not get any collision callback. Things might go through each other. You can try predicting the collision before it happens using the velocity and deltaTime, but it's still not going to be enough and you will end up reinventing the wheel.</p> <p>Mario's SuperJumper is a great demo to start libGDX. Try it. </p> <p><strong>EDIT:</strong></p> <p>Have an instance member-</p> <pre><code>Vector3 touchPoint; </code></pre> <p>On create-</p> <pre><code>touchPoint = new Vector3(); </code></pre> <p>On update-</p> <pre><code>camera.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0)); if (Gdx.input.justTouched()) { if (pointInRectangle(rectangle, touchPoint.x, touchPoint.y)) { } } </code></pre> <p>Please take note of the coordinate system in libGDX. For testing, create one rectangle on screen. On click, print/debug the coordinates of both the rectangle and touchPoint.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload