Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

This is something I've been wondering for quite a while. When building games that exist out of multiple levels (platformers, shmups etc) what is the prefered method to switch between the levels?

Let's say we have a level class that does the following:

  • Load data for the level design (tiles), enemies, graphics etc.
  • Setup all these elements in their appriopate locations and display them
  • Start physics and game logic

I'm stuck between the following 2 methods:

1: Throw away everything in the level class and make a new one, we have to load an entirely new level anyway!

2: pause the game logic and physics, unload all currents assets, then re-initialize those components with the level data for the new level.

They both have their pros and cons. Method 1 is alot easier and seems to make sense since we have to redo everything anyway. But method 2 allows you to re-use exisiting elements which might save resources and allows for a smoother transfer to the new level.

share|improve this question
    
What resources would you be saving and what existing elements are you reusing? From your description, it seems that method 2 is method 1 except you don't explicitly create a new instance of level. Don't you have to pause logic and physics, then reinitialize components with the new level data in both cases? –  Chewy Gumball Jun 26 '11 at 3:58
    
It is indeed the same method, with the only difference being to create a new instance or not. Creating a new instance would throw away the world and grid and set them up completetly from scratch again, opposed to unloading stuff in the world and grid and have their main structure still stand intact (not having to create a new array for the grid for example). Both ways work, I was mainly wondering what method is normally used. –  omgnoseat Jun 27 '11 at 14:40

2 Answers 2

If your physics and game logic has little initialization or does not need any information from the last level stored, then the effect of throwing it away is negligible.

If the above is not true, or if you have a large amount of shared assets, I would pause the gameplay.

Another option is to copy the shared assets over to the new level and delete all the old unwanted ones, and do method 1. This probably is only a benefit if there is a large amount of shared assets.

share|improve this answer
1  
Thats an interesting point, with the shared assets. There are alot of shared assets, but they all have alot of properties that are being changed throughout the game. That would mean I would have to reset all those properties and that kind of defeats the point of reusing it I guess. –  omgnoseat Jun 27 '11 at 14:42

It simply depends on the type of game you are working on. If it requires you to have smooth transitions or to stream the content of a level (like in crysis for example) then you should go for the second method.

This question is rather vague... For a platformer I'd recommend to create a new level from scratch, because you are likely to have seperate levels in seperate files...

share|improve this answer
1  
It's not vague, IMHO. It is clear..and Crysis's streaming is not the same as switching levels. –  The Communist Duck Jun 26 '11 at 9:33
    
So by "smoother" you mean shorter loading times? –  Felheart Jun 26 '11 at 11:53
    
The levels are indeed in different files, but I could still pause the game, load the new level and pass that data into the existing world. Smooth transitions are interesting though, I just have to call mortal kombat here, the transitions in that game are so nice! Think I'm going to give that a go, unless I encounter problems, which I wil report here. –  omgnoseat Jun 27 '11 at 14:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.