简体   繁体   English

在XNA / WP7游戏的SpriteBatch中重绘Sprite

[英]Redrawing sprites in a spritebatch in xna/wp7 game

I am doing a little game for wp7 and I was wondering how to redraw a sprite within a spritebatch. 我正在为wp7做一个小游戏,我想知道如何在spritebatch中重绘一个sprite。 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. 我尝试再次调用spritebatch.draw(),其参数用于标题页,但它只是跳过了代码,就好像没有这样做一样。

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. 假设您正在使用“屏幕”方法来组织代码(即[游戏状态管理]) 1 ,只需将它们重定向到标题屏幕,标题屏幕就会从那里开始。

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. 正如前面的答案所提到的,执行此操作的一种常见方法是拥有一种管理游戏状态的方法。

Ie SpashScreenState, InGameState, MenuState, GameOverState 即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. 这些状态中的每一个都实现IGameState或某些东西,然后将它们全部包含在某个GameStateManager或某些东西中,因此您可以在任何给定时间在状态之间进行切换,并且只会更新活动状态。

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... 如果您具有透明菜单,或者希望游戏在不显示游戏的情况下继续在后台运行,则可能会有些棘手,但是我相信XNA网站上有一些以这种方式处理状态的教程...

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. 然后有一个字典来存储您所有的游戏状态,然后在XNA主要部分中有一个变量来存储当前游戏状态,然后只需将所有更新/渲染调用重定向到字典中的相关值即可。

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. 这样,一次只能激活一个游戏状态,这意味着如果您转到菜单然后返回游戏,您将精确地从上次退出的位置开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM