且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在没有scene2d的情况下检测是否触摸了纹理libgdx

更新时间:2023-02-01 22:55:15

当然有,我也没用screne2d.

Of course there is, I also never use screne2d.

在您的更新方法中

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