Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8256153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:45:57+00:00 2026-06-08T01:45:57+00:00

I’m coding my first game with XNA and i’m a bit confused. The game

  • 0

I’m coding my first game with XNA and i’m a bit confused.

The game is a 2D platform game, in pixel-perfect, NOT Tiles based.

Currently, my code looks like this

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
}

Every sprites are loaded since the beginning, so it’s not a good idea for the computer’s RAM.

Well, Here are my questions :

  • How can i save a level with his own number of sprites, their events and objects ?
  • How can i load/unload these levels ?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:46:00+00:00Added an answer on June 8, 2026 at 1:46 am

    Give each level its own ContentManager, and use that instead of Game.Content (for per-level content).

    (Create new ContentManager instances by passing Game.Services to the constructor.)

    A single ContentManager will share all instances of content that it loads (so if you load “MyTexture” twice, you will get the same instance of it both times). Due to this fact, the only way to unload content is to unload the entire content manager (with .Unload()).

    By using multiple content managers, you can get more granularity with unloading (so you can unload the content for just a single level).

    Just note that different instances of ContentManager don’t know about each other and won’t share content. For example if you load “MyTexture” on two different content managers, you get two separate instances (so you use twice the memory).

    The simplest way to deal with this is to load all the “shared” stuff with Game.Content, and all the per-level stuff with the separate level content managers.

    If this still doesn’t provide enough control, you can derive a class from ContentManager and implement your own load/unload policies (example in this blog post). Although this is rarely worth the effort.

    Remember that this is an optimisation (for memory) – so don’t spend too much time on it until it becomes an actual issue.

    I recommend reading this answer (on the gamedev site) that provides some tips and links to further answers that explain in more depth how ContentManager works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I am currently running into a problem where an element is coming back from
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.