如何检测纹理是否被触摸libgdx WITHOUT scene2d



我想知道是否有一种方法可以在不使用scene2d的情况下检测到特定纹理上的触摸。Gdx.input.isTouched()检测整个屏幕上的触摸,是否有一种方法,我可以使用的东西,检测触摸纹理没有scene2d?

当然有,我也从不使用screen2d。

中的更新方法

  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
     }
}

最新更新