2017-03-05 9 views
0

私はlibGDXでゲームを開発しています。私は質問があります:最初の座標と目標座標を知って、写真が示すように、どのように弾丸の放物線効果を達成するために?シェルの操作を達成する。誰が私を教えることができますか?またはチュートリアルを教えてください。 TKSlibGDXで次のような効果を得るには?

絵アプリ(例:BOX2D)にいくつかの物理学を追加する必要が

enter image description here

+0

これらを実装するにはBox2Dが必要です。 – Sparcsky

+0

特定のターゲットに当たる初期速度を決定するには、基本的な大学の新入生レベル計算が必要だと思います。 – Tenfour04

+0

これはlibgdxとは関係ありませんが、これは基本的な物理学です。 – Hllink

答えて

0

。次に、ある速度とある方向/角度でキャノンボールを投げる。 物理エンジンはあなたのために休息します。 ここにはbox2dのチュートリアルがあります:https://www.youtube.com/watch?v=vXovY2KTing

box2dを使わないで非常に基本的な例です。あなたの例では、目標位置の正しいパワーを計算する必要があります。

public class SampleApp extends ApplicationAdapter 
{ 
    Sprite sprite; 
    Vector2 velocity = new Vector2(0, 0); 
    Vector2 terminateVelocity = new Vector2(2000, 2000); 
    Vector2 friction = new Vector2(200, 300); 
    Vector2 position = new Vector2(0, 0); 
    Vector2 launchPower = new Vector2(0, 0); 
    boolean shotNow; 

    @Override 
    public void render() 
    { 
     update(Gdx.graphics.getDeltaTime()); 
     // ... 
     // here render your stuff 
    } 

    public void shot(float power) 
    { 
     // Calculate x launch power 
     launchPower.x = ((power - sprite.getX() + sprite.getWidth()*0.5f)/2f) + velocity.x; 
     // We want to end our fly at ground 
     launchPower.y = ((0 - sprite.getY())/2f) + velocity.y; 
     // Setup start position 
     position.x = sprite.getX(); 
     position.y = sprite.getY(); 
     // Add some acc to velocity 
     velocity.add(launchPower); 
     shotNow = true; 
    } 

    public void update(float dt) 
    { 
     if (Gdx.input.justTouched()) { 
      shot(900); 
     } 
     // Very basic sprite movement. 
     // For best results you should implement more physics (acceleration etc.) 
     if (shotNow && position.y > 0) { 
      // Friction/gravity 
      velocity.x = MathUtils.clamp(velocity.x - friction.x * dt, -terminateVelocity.x, terminateVelocity.x); 
      velocity.y = MathUtils.clamp(velocity.y - friction.y * dt, -terminateVelocity.y, terminateVelocity.y); 
      position.add(velocity.x * dt, velocity.y * dt); 
      sprite.setPosition(position.x, position.y); 
     } 
    } 
} 
関連する問題