Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a method that checks if an libgdx Scene2d Image or Actor is touched?
    text
    copied!<p>here's my sample from the libgdx android game that I want to create. Nothing special yet, cause I'm just starting my adventure with Android games.</p> <p>Here is a couple of questions I would like to get answered</p> <p>So far I am using the Gdx.input.isTouched function and check if that matches the bunny coordinates, I do that for each bunny and at the end I would like to have 11 of them and that's just too much to write. Is there a way to check if the Image class from import com.badlogic.gdx.scenes.scene2d.ui.Image; was touched? Or else does the Actor class has that feature?</p> <p>Another thing is that when I instantiate the bunny class and I click the bunny, all of them are changing to "scared". It's because the Scene2d.Image texture has to be static. Is there a way to change that?</p> <pre><code>if(Gdx.input.isTouched()){ x = Gdx.input.getX(); y = Gdx.graphics.getHeight() - Gdx.input.getY(); // **** Show Coordinates **** \\ if (x &lt; 420) font.draw(batch, "x:" + x + "\n y: " + y, x, y); else font.draw(batch, "x:" + x + " y: " + y, x-65, y); // **** End Show Coordinates **** \\ //if krolik (bunny) is touched add highscore and change texture to scared if (x &gt;= krolik.pos.x &amp;&amp; y &gt;= krolik.pos.y &amp;&amp; x &lt;= krolik.pos.x + 64 &amp;&amp; y &lt;= krolik.pos.y + 64) { krolik.scared(); highscore+=100; } else if (x &gt;= krolik2.pos.x &amp;&amp; y &gt;= krolik2.pos.y &amp;&amp; x &lt;= krolik2.pos.x + 64 &amp;&amp; y &lt;= krolik2.pos.y + 64) { krolik2.scared(); highscore+=100; } } else{ krolik.normal(); } // **** Show Highscore **** \\ font.draw(batch, "Highscore: " + highscore, 350, 300); batch.draw(krolik.getTexture(), krolik.pos.x, krolik.pos.y); batch.draw(krolik2.getTexture(), krolik2.pos.x, krolik2.pos.y); batch.end(); </code></pre>
 

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