开发者

Redrawing sprites in a spritebatch in xna/wp7 game

I am doing a little game for wp7 and I was开发者_StackOverflow社区 wondering how to redraw a sprite within a spritebatch. More specifically, after the game is over and the high score screen is drawn if they hit the back button or in a specific area of the screen the title page would be redrawn and they could start playing the game again without exiting the game. I tried calling spritebatch.draw() again with the parameters being for the title page but it just skips over the code as if it did it and it doesn't.

Thanks so much.


Assuming you're using the "Screen" method of organizing your code (ie. [Game State Management])1, simply redirect them to the title screen and the title screen will take it from there.

If you are not using the game state management, then you will need to be more specific, otherwise, I'd suggest just reformatting your code to use the method described in the link above.


I think you need to look at separating your logic out a bit more. As the previous answer mentioned a common way of doing this is to have a way to manage your game states.

I.e SpashScreenState, InGameState, MenuState, GameOverState

Each of those states implementing an IGameState or something, then just have them all contained within some GameStateManager or something, so you can hop between the states at any given time and only that active state would be updated.

It can get a bit tricky if you have transparent menus, or want the game to continue in the background without displaying the game, but I believe the XNA site has some tutorials on handling state this way...

The SIMPLEST way of getting it working is to have something like below:

public enum GameState
{
    Unknown = 0,
    SplashScreen,
    InGame,
    Menu,
    GameOver    
}

public interface IGameState
{
    void Init();
    void Update(GameTime elapsedTime);
    void Render(GameTime elapsedTime);
    void Destroy();
}

Then have a Dictionary which stores all your game states, then within your XNA main section have a variable to store the current game state, then just redirect all your update/render calls to the relevant value in the dictionary.

This is a REALLY primitive way of doing it, but should show you the overall idea behind separating it out into different game states. As this way only one game state can be active at once, meaning if you go to the menu then back to the game you will resume exactly where you left off.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜