Button XNA:条件抽签

Button XNA:条件抽签,button,xna,Button,Xna,我在WP7上做游戏。我在里面加了一个按钮。我想做的是,每当我触摸按钮时,按钮精灵应该将其帧从0更改为1,0为按钮向上帧,1为按钮按下帧。我已经为按钮添加了精灵表,它只包含两个帧。尺寸也可以 总而言之,我想这样做: 1当触摸按钮时 按下2个按钮的框架应被拉出,并在1或2秒后回到原始框架。就像每一个有按钮的游戏一样。听起来更像是设计问题,而不是实现问题。基本上,你需要一个开始的想法。我不太熟悉WP7,但我将向您展示可以使用的基本设计;使用一些sudo代码,您可以稍后填写 class Button {

我在WP7上做游戏。我在里面加了一个按钮。我想做的是,每当我触摸按钮时,按钮精灵应该将其帧从0更改为1,0为按钮向上帧,1为按钮按下帧。我已经为按钮添加了精灵表,它只包含两个帧。尺寸也可以

总而言之,我想这样做:

1当触摸按钮时
按下2个按钮的框架应被拉出,并在1或2秒后回到原始框架。就像每一个有按钮的游戏一样。

听起来更像是设计问题,而不是实现问题。基本上,你需要一个开始的想法。我不太熟悉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);
    }
}
注意:您尚未测试此代码 希望这能帮助你入门,如果你想了解更多关于某个特定部分的信息,请随时详细说明。 马克斯