複数のウェイポイントを介してスプライトのコースを決定するために、A *パス探索を実装しました。私はポイントAからポイントBの場所でこれを行っていますが、複数のウェイポイントに問題があります。なぜなら、遅いデバイスではスピードが遅くなり、スプライトはウェイポイントを過ぎて移動します。経過時間に渡る複数行の経路による座標ベースの移動
EDIT:パス発見コードをゲームスレッドで分けるために、このonUpdateメソッドは、スプライト更新用のUIスレッドで発生するクラスのようなスプライトに存在します。さらに明確にするために、オブジェクトがマップをブロックするときにのみパスが更新されます。現在のパスは変更できますが、誤っていなければアルゴリズムの設計に影響はありません。私はさておき、この作品から、関連するすべてのコンポーネントがうまく設計され、正確であると信じています: - )
ここではシナリオです:
public void onUpdate(float pSecondsElapsed)
{
// this could be 4x speed, so on slow devices the travel moved between
// frames could be very large. What happens with my original algorithm
// is it will start actually doing circles around the next waypoint..
pSecondsElapsed *= SomeSpeedModificationValue;
final int spriteCurrentX = this.getX();
final int spriteCurrentY = this.getY();
// getCoords contains a large array of the coordinates to each waypoint.
// A waypoint is a destination on the map, defined by tile column/row. The
// path finder converts these waypoints to X,Y coords.
//
// I.E:
// Given a set of waypoints of 0,0 to 12,23 to 23, 0 on a 23x23 tile map, each tile
// being 32x32 pixels. This would translate in the path finder to this:
// -> 0,0 to 12,23
// Coord : x=16 y=16
// Coord : x=16 y=48
// Coord : x=16 y=80
// ...
// Coord : x=336 y=688
// Coord : x=336 y=720
// Coord : x=368 y=720
//
// -> 12,23 to 23,0 -NOTE This direction change gives me trouble specifically
// Coord : x=400 y=752
// Coord : x=400 y=720
// Coord : x=400 y=688
// ...
// Coord : x=688 y=16
// Coord : x=688 y=0
// Coord : x=720 y=0
//
// The current update index, the index specifies the coordinate that you see above
// I.E. final int[] coords = getCoords(2); -> x=16 y=80
final int[] coords = getCoords(...);
// now I have the coords, how do I detect where to set the position? The tricky part
// for me is when a direction changes, how do I calculate based on the elapsed time
// how far to go up the new direction... I just can't wrap my head around this.
this.setPosition(newX, newY);
}
gamedevで投稿をクロスしないでください。どちらか一方に投稿する。 – AttackingHobo