2012-03-03 11 views
0

私はWP7でゲームをしています。私はそれにボタンを追加しました。私がしたいことは、ボタンに触れるたびに、ボタンスプライトはそのフレームを0から1に変更する必要があります(0はボタンアップフレーム、1はボタン押下フレームです)。私は2つのフレームだけを含むボタンのスプライトシートを追加しました。サイズも大丈夫です。タッチボタン 2)ボタンを押すフレームが描画され、1または2秒後に元のフレームに来るべきであるとき)XNA:条件付き抽選

1:私はこれをやりたい、まとめての

。 (ちょうどボタンを持つすべてのゲームで起こるように)。

答えて

0

さらに、設計上の問題のように聞こえ、実装の問題が発生します。基本的には、あなたが始めるためのアイデアが必要です。私はWP7について詳しくは分かりませんが、使用できる基本的なデザインを紹介します。後に記入できるsudoコードがあります。

class Button 
{ 
    private Point CellSize; 
    public Point Position {get; set;} 

    private Texture2D buttonSheet; 

    public Button (Texture2D texture, Point CellSize) 
    { 
     this.buttonSheet = texture; 
     this.CellSize = CellSize; 
    } 

    public bool isPressed {get; private set;} 

    public void Update (bool isPressed) 
    { 
     this.isPressed = isPressed; 
    } 

    public void Draw (SpriteBatch sb) 
    { 
     Rectangle Source = new Rectangle (0,0,CellSize.X,CellSize.Y); 
     if (this.isPressed) 
      Source = new Rectangle (CellSize.X * 1, CellSize.Y * 1, CellSize.X, CellSize.Y); 
     sb.Draw (this.buttonSheet, new Rectangle(this.Position.X,this.Position.Y,CellSize.X,CellSize.Y), Source, Color.White); 
    } 
} 

そしてそれを使用する:

class Game1 
{ 
    Button Start = new Button(new Texture2D() /*load and include your texture here*/, new Point (100, 50) /* 100 wide, 50 tall cells */); 
    public Update (GameTime gt) 
    { 
     bool clicked = false /* Put code here to check if the button is pressed */; 
     Start.Update(clicked); 
    } 

    public Draw (SpriteBatch spriteBatch) 
    { 
     Start.Draw(spriteBatch); 
    } 
} 

(ノートは、このコードをテストしていない)
希望あなたが特定の詳細が必要な場合は手の込んだ気軽に、あなたが始めるのに役立ちます部。
最大