あなたが知る必要があるのは、画面がタッチされた順にAndroidがインデックスを分けていることです。インデックスは「ポインタ」として知られています。たとえば、1本の指で画面をタッチすると、タッチポインターは0になり、2番目のタッチポインターは1になります。libGDXが登録する最も高いポインターは20です。
特定の状況では、現在タッチを読み取っている最も高いポインタ上の入力であり、最も高いタッチを読み取っているintを有する。あなたは、ポインタによるループができ、イベントが実際にこのような最新のプレスを参照している最高のポインタであるものは何でもタッチにINTを設定する:あなたはおそらくあなたのボタンを描画する別のカメラをお勧めします
int highestpointer = -1; // Setting to -1 because if the pointer is -1 at the end of the loop, then it would be clear that there was no touch
for(int pointer = 0; pointer < 20; pointer++) {
if(Gdx.input.isTouched(pointer)) { // First check if there is a touch in the first place
int x = Gdx.input.getX(pointer); // Get x position of touch in screen coordinates (far left of screen will be 0)
if(x < arrowMoveWhite.getWidth() + 40 || x >= arrowMoveX - 40) {
highestpinter = pointer;
} // Note that if the touch is in neither button, the highestpointer will remain what ever it was previously
}
} // At the end of the loop, the highest pointer int would be the most recent touch, or -1
// And to handle actual movement you need to pass the highest pointer into Gdx.input.getX()
if(!isPlayerHit) { // Minor improvement: only check this once
if(Gdx.input.isKeyPressed(Keys.RIGHT) || (highestpointer > -1 && Gdx.input.getX(highestpointer) >= arrowMoveX - 40)) {
x+=SPEED*Gdx.graphics.getDeltaTime();
} else if(Gdx.input.isKeyPressed(Keys.LEFT) || (highestpointer > -1 && Gdx.input.getX(highestpointer) < arrowMoveWhite.getWidth() + 40)) {
x-=SPEED*Gdx.graphics.getDeltaTime();
}
}
注意xが同じ方向に向いているので、スクリーン座標をワールド座標に変換することについて心配する必要がないので、(または任意のhud要素)
どのように動作するのか、変更が必要な場合はお知らせください。
'lastTouchedDirection'整数またはブール値フラグを作成します。いずれかのボタンが押されたときにフラグを更新します。位置を更新するときは、このフラグをチェックして、移動する方向を決定します。あなたはあなたの動きのステートメントのいくつかの条件を抽出する必要があります。 –
これは私が試した最初のものでしたが、そのようには機能しません。どのボタンが押されているかが絶えず確認されますので、右ボタンをタッチするとこのフラグを1に設定し、左ボタンをタッチすると0に設定します。右ボタンを押している間、フラグは常に1に設定されているので、左ボタンを押すと0に設定されますが、右ボタンの条件は真ですので、フラグは再び1に設定されます。私は知っているが... ...:D –
両方のボタンが押されている(タッチされていない)かどうかを同時にチェックしなければならないと思う。 –