さらに、設計上の問題のように聞こえ、実装の問題が発生します。基本的には、あなたが始めるためのアイデアが必要です。私は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);
}
}
(ノートは、このコードをテストしていない)
希望あなたが特定の詳細が必要な場合は手の込んだ気軽に、あなたが始めるのに役立ちます部。
最大
出典
2012-03-04 03:32:22
Ben