gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 07:26:14 25 4
gpt4 key购买 nike

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

最佳答案

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

在您的更新方法中

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

关于libgdx - 如何在没有scene2d的情况下检测纹理是否已被触摸libgdx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24834399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com