2011-06-21 4 views
0

複数のウェイポイントを介してスプライトのコースを決定するために、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); 
} 
+1

gamedevで投稿をクロスしないでください。どちらか一方に投稿する。 – AttackingHobo

答えて

0

私の提案はonUpdate()のから経路探索コードを取ることであろうと、よく更新されました。 onUpdate()は、更新時の位置で動作するだけであり、現在の位置に対する実際の計算は、より速い速度で他の場所で行われることになる。しかし、これはおそらくスレッドを必要とするでしょう。

最も簡単な解決策は、個々のフレームカウントを1つの「ティック」として持つことです。その後、ゲームは低速のシステムではより低速で実行されますが、フレームからフレームへのすべての計算はフレームレート。私はあなたがその行動を望んでいるとは思わない。

+0

私はゲームの実際のデザインのビットを明確にした。実際にはすべてのデバイスが同じ時間スケールで動作することが重要ですが、お返事いただきありがとうございます。 – Chris

関連する問題