パララックス スクロールに関しては、PFG が既に行った以上に言うことはありません。実際、リポジトリの test フォルダーの下に例があり、Web 上のいくつかの説明があります。私はこれが好きでした。背景の問題は本当に簡単に解決できます。この問題およびその他の関連する問題は、剰余代数を使用してアプローチできます。一度見れば非常にわかりやすいので、詳細には触れません。
画面にコンパスを表示したいとします。基点を表すテクスチャ 1024x16 があります。基本的に持っているのはストリップだけです。実際の向きなどの考慮事項はさておき、レンダリングする必要があります。
たとえば、ビューポートが 300x400 で、画面上に 200px のテクスチャが必要です (より興味深いものにするため)。位置 (1024-200) = 824 に到達するまで、単一の領域で完全にレンダリングできます。この位置に到達すると、明らかにテクスチャがなくなります。でも羅針盤なので、最後まで来たらまた始めなければならないのは明らかです。これが答えです。別のテクスチャ領域でうまくいきます。825 ~ 1023 の範囲は、別の領域で表す必要があります。2 番目の領域のサイズは、すべての値 pos>824 && pos<1024 に対して (1024-pos) になります。
このコードは、コンパスの実際の例として機能することを意図しています。範囲 (0-3.6) から (0-1024) への変換により、常に相対位置で動作するため、非常に汚れています。
spriteBatch.begin();
if (compassorientation<0)
compassorientation = (float) (3.6 - compassorientation%3.6);
else
compassorientation = (float) (compassorientation % 3.6);
if ( compassorientation < ((float)(1024-200)/1024*3.6)){
compass1.setRegion((int)(compassorientation/3.6*1024), 0, 200, 16);
spriteBatch.draw(compass1, 0, (Gdx.graphics.getHeight()/2) -(-250 + compass1.getTexture().getHeight()* (float)1.2), Gdx.graphics.getWidth(), 32 * (float)1.2);
}
else if (compassorientation > ((float)(1024-200)/1024*3.6)) {
compass1.setRegion((int)(compassorientation/3.6*1024), 0, 1024 - (int)(compassorientation/3.6*1024), 16);
spriteBatch.draw(compass1, 0, (Gdx.graphics.getHeight()/2) -(-250 + compass1.getTexture().getHeight()* (float)1.2), compass1.getRegionWidth()/200f * Gdx.graphics.getWidth() , 32 * (float)1.2);
compass2.setRegion(0, 0, 200 - compass1.getRegionWidth(), 16);
spriteBatch.draw(compass2, compass1.getRegionWidth()/200f * Gdx.graphics.getWidth() , (Gdx.graphics.getHeight()/2) -(-250 + compass1.getTexture().getHeight()* (float)1.2), Gdx.graphics.getWidth() - (compass1.getRegionWidth()/200f * Gdx.graphics.getWidth()) , 32 * (float)1.2);
}
spriteBatch.end();