Jump to content
  • Advertisement
Sign in to follow this  
MohannadAl-Hmoud

Optimizing Speed in XNA when switching levels

This topic is 2768 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

I am trying to create a game that has an array of 30 levels, I am trying to optimize the switching between levels, but using a switch case to switch levels from 0-29 is seriously long, is there a possible way to create nested cases as follows in C#?

***PSUEDO CODE***

switch(i)
{
case <10:
{
switch(i)
case 1: { break;}
case 2: { break;}
case 3: { break;}
...etc
}
case <20:
...
}
etc,
that would reduce the Big-O of the switch case, but I can't find the code to make it work, can somebody give me a hand here?

thanks

Share this post


Link to post
Share on other sites
Advertisement
What are you actually doing inside these massive switch statements? I don't understand why you have a massive switch statement for changing levels. What sort of code is inside each of those switch statements?

Also, you can't do what you seem to want to do with switch statements. It shouldn't matter though, switch statements are not slow. You're optimizing the wrong part of your code, I think.

Share this post


Link to post
Share on other sites
I don't see the need to nest the switch statement here, surely you're just adding several more lines to a piece of code that's already too long?

What you could do is have an array of levels 1-30. Then when you want to load a specific level you would just do:

levelArray.load()

or whatever your code looks like.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!