5
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ 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? \$\endgroup\$ Commented Jun 26, 2011 at 3:58
  • \$\begingroup\$ 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. \$\endgroup\$
    – omgnoseat
    Commented Jun 27, 2011 at 14:40

2 Answers 2

2
\$\begingroup\$

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.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – omgnoseat
    Commented Jun 27, 2011 at 14:42
1
\$\begingroup\$

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...

\$\endgroup\$
3
  • 1
    \$\begingroup\$ It's not vague, IMHO. It is clear..and Crysis's streaming is not the same as switching levels. \$\endgroup\$ Commented Jun 26, 2011 at 9:33
  • \$\begingroup\$ So by "smoother" you mean shorter loading times? \$\endgroup\$
    – Riki
    Commented Jun 26, 2011 at 11:53
  • \$\begingroup\$ 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. \$\endgroup\$
    – omgnoseat
    Commented Jun 27, 2011 at 14:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .