如何在没有scene2d的情况下检测是否已触摸纹理libgdx [英] How to detect if a texture has been touched libgdx WITHOUT scene2d
本文介绍了如何在没有scene2d的情况下检测是否已触摸纹理libgdx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有无需使用scene2d就能检测到某种纹理的触摸的方法. Gdx.input.isTouched()在整个屏幕上检测到触摸,是否可以使用某种方法在没有scene2d的情况下检测出纹理上的触摸?
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?
推荐答案
当然有,我也从不使用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
}
}
这篇关于如何在没有scene2d的情况下检测是否已触摸纹理libgdx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文