I want to know if there is a away to detect a touch on a certain texture without using scene2d. The Gdx.input.isTouched() detects a touch on the WHOLE screen, is there a way i could use something that detects a touch on a texture without scene2d?
Of course there is, I also never use screne2d.
in your update method
if(Gdx.input.isTouched())
{
Vector3 tmp=new Vector3(Gdx.input.getX(),Gdx.input.getY();
camera.unproject(tmp);
Rectangle textureBounds=new Rectangle(textureX,textureY,textureWidth,textureHeight);
// texture x is the x position of the texture
// texture y is the y position of the texture
// texturewidth is the width of the texture (you can get it with texture.getWidth() or textureRegion.getRegionWidth() if you have a texture region
// textureheight is the height of the texture (you can get it with texture.getHeight() or textureRegion.getRegionhHeight() if you have a texture region
if(textureBounds.contains(tmp.x,tmp.y))
{
// you are touching your texture
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With