2016-06-21 4 views
1

私はに1つのゲーム画面で2つのスプライトオブジェクトにモーションを追加したい。私は2つのスプライトオブジェクトは、Libgdxを使用して、アプリケーションの1ページまたはゲーム画面で独立して移動する(またはいくつかの事前定義されたパスに従う)必要があることを意味します。どうすればそれを達成できますか? 私を助けてください。可能であれば、参考コードも記入してください。ありがとうございました。android libgdxの1画面で2つのスプライトオブジェクトを移動するには?

+0

レンダリング方法から座標を変更するだけです。もう何か試しましたか?何が問題ですか? – MilanG

答えて

0

この目的のためにscene2dを使用することができます。ここでは、アクションを通じてオブジェクトを簡単に移動できます。 これらのリンクをたどって、scene2dを学ぶことができます。私はこれらのリンクはあなたを助けることを願っています

http://www.gamefromscratch.com/post/2013/11/27/LibGDX-Tutorial-9-Scene2D-Part-1.aspx

http://www.gamefromscratch.com/post/2013/12/09/LibGDX-Tutorial-9-Scene2D-Part-2-Actions.aspx

あなたがこれを行うことができます
0

は2つの2DVectorオブジェクトを取る:

private Vector2 positiononesprite,positiontwosprite; 
Sprite sprite_one,sprite_two; 

は、あなたの方法を作成し、この

positiononesprite = new Vector2(0,0); 
positiontwosprite = new Vector2(0,0); 

//set your sprite position 
sprite_one.setPosition(x,y);//your x and y coordinates 
sprite_two.setPosition(x1,y1);//your second sprite postions 

positiononesprite.x = sprite_one.getX(); 
positiononesprite.y = sprite_one.getY(); 

positiontwosprite.x = sprite_two.getX(); 
positiontwosprite.y = sprite_two.getY(); 

/* 
then to make them move in a custom direction you can use either 
setPosition method or translate method*/ 

//apply your algorithm on vectors and set or translate your sprites 
// in render method define there speed, direction and move them 
//for example i did this to move it in a particular direction 

pointerposition.x += directionpointer.x * speed; 
      pointerposition.y += directionpointer.y * speed; 

      // pointer.setPosition(pointerposition.x, pointerposition.y); 
      ball.setPosition(pointerposition.x, pointerposition.y); 

はこのここに特定の方向 に私のボールを動かしていますかdirectionpointerは方向ベクトルで、speedはfloat変数で、pointerpositionはpositiononespriteと宣言したvector2オブジェクトです

関連する問題