我正在用XNA编码我的第一款游戏,而且我有点困惑。如何加载和卸载关卡
该游戏是一个2D平台游戏,以像素为完美,不是基于瓷砖。
目前,我的代码看起来像这样
public class Game1 : Microsoft.Xna.Framework.Game
{
//some variables
Level currentLevel, level1, level2;
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
//a level contains 3 sprites (background, foreground, collisions)
//and the start position of the player
level1 = new Level(
new Sprite(Content.Load<Texture2D>("level1/intro-1er-plan"), Vector2.Zero),
new Sprite(Content.Load<Texture2D>("level1/intro-collisions"), Vector2.Zero),
new Sprite(Content.Load<Texture2D>("level1/intro-decors-fond"), Vector2.Zero),
new Vector2(280, 441));
level2 = new Level(
new Sprite(Content.Load<Texture2D>("level2/intro-1er-plan"), Vector2.Zero),
new Sprite(Content.Load<Texture2D>("level2/intro-collisions"), Vector2.Zero),
new Sprite(Content.Load<Texture2D>("level2/intro-decors-fond"), Vector2.Zero),
new Vector2(500, 250));
...//etc
}
protected override void UnloadContent() {}
protected override void Update(GameTime gameTime)
{
if(the_character_entered_zone1())
{
ChangeLevel(level2);
}
//other stuff
}
protected override void Draw(GameTime gameTime)
{
//drawing code
}
private void ChangeLevel(Level _theLevel)
{
currentLevel = _theLevel;
//other stuff
}
从一开始每个精灵被加载,所以它不是计算机的RAM是个好主意。
好了,这里是我的问题:
- 我怎样才能保存自己的数字精灵,它们的事件和对象的水平?
- 如何加载/卸载这些级别?
你说得对,我不应该浪费太多时间。但总是很高兴知道。 Thx对于所有这些信息都很重要。 – Sharpnel 2012-07-21 12:25:04
奖励:在游戏关卡文件中,您应该保密和完整。前者为了避免用户在文件内部偷看以在实际播放它之前知道该级别,后者避免用户改变级别数据以便在玩它时获得一些益处 – 2014-04-17 21:17:36