2012-03-08 3 views
0

ゲームを作成したいが、問題がある。私は2つの画像を描きたい。 TextureとSpriteBatchを使用して2つの画像を描画しました。しかし、今私はいくつかのアクションを実装したい。私はユーザーのためのmessegeを作成したい。彼が最初のイメージをクリックすると、彼はメッセージを受け取る。あなたの選択はpicture1である。他の画像アルゴリズムでも同じです。libgdxとモーションアクション

public void create() { 
    background = new Texture(Gdx.files.internal("backg.png")); 
    polishFlag = new Texture(Gdx.files.internal("german.png")); 
    englishFlag = new Texture(Gdx.files.internal("english.png")); 
    batch = new SpriteBatch(); 
} 
public void render() { 
    batch.begin(); 
    batch.draw(background, 0, 0, 480, 320); 
    batch.draw(germanFlag, 140,80, 90, 60); 
    batch.draw(englishFlag, 260,80, 90, 60); 
    batch.end(); 
} 

この機能はどのように実装できますか?私はアンドロイドプラットフォーム上でこのソリューションの作業にしたい。いくつかのアイデア?

答えて

1

InputProcessorインターフェイスを見てみましょう。 (または、InputMultiplexerクラスを使用します)。

public class YourGame implements InputProcessor{ 
     com.badlogic.gdx.math.Rectangle touchBounds; 
     string message ; 
     BitmapFont font; 

     //lots of input processor methods 
     @Override 
     public boolean onTouchDown(x, y, int button){ 
      tocuhBounds.x = 140; 
      if (rectangle.contains(x,y)) 
       message = "your choice is picture1"; 
      else{ 
       touchBounds.x = 260; 
       if (rectangle.contains(x,y)) 
       message = "your choice is picture2"; 
      } 
     } 

     public void create() { 
      background = new Texture(Gdx.files.internal("backg.png")); 
      polishFlag = new Texture(Gdx.files.internal("german.png")); 
      englishFlag = new Texture(Gdx.files.internal("english.png")); 
      batch = new SpriteBatch(); 
      touchBounds = new Rectangle(); 
      touchBounds.width = 90; 
      touchBounds.height = 60; 
      touchBounds.y = 80; 
      font = new BitmapFont(); 
     } 

     public void render() { 
      batch.begin(); 
      batch.draw(background, 0, 0, 480, 320); 
      batch.draw(germanFlag, 140,80, 90, 60); 
      batch.draw(englishFlag, 260,80, 90, 60); 
      font.draw(batch, message, 10, 10); 
      batch.end(); 
    } 

} 
:あなたのような何かができるInputProcessorを使用して