![](/img/trans.png)
[英]Best way to detect the touched object (moving) from collection in libgdx
[英]Moving object when is touched
我使用以下代碼移動對象:
if (Gdx.input.isTouched())
{
gameObject1.y=Gdx.graphics.getHeight()-Gdx.input.getY() + 30;
gameObject1.x=Gdx.input.getX() + 30;
}
但是在這種情況下,觸摸屏幕時對象會移動。 在LibGdx中,單擊或按下此對象時移動對象的簡單方法是什么? 類似於上面的代碼?
最簡單的方法可能是為此使用scene2d
。 它具有基於事件系統的命中檢測功能,您可以通過將偵聽器附加到Actors
來使用。
另一種方法是結合使用Intersector
和Rectangle
作為邊界框,然后自己進行命中檢測。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.