I am still learning and I am trying to design the game levels for my first game (a platformer).

I have some straightforward questions because I feel I am on the wrong way.

Should each level have its own class ?

The way I am trying to do this is, when one finishes the first level I set all variables to null that belong to that class, unregister all events and remove all children from the stage, call a second level constructor, without declaring any variable, new level2(); and set a static var to true "in order to save" that progress in case one wants to play that level again.

However I see the code becomes messy, I run into issues, and memory management concerns arise.

I searched for help all over the internet but I can't find any tutorial that explain it in details, so I'm trying out many ways of achieving what I want, but now I am really in need of some advices to not get lost.

  • \$\begingroup\$ What exactly is your question? How to purge a level from memory once it's done, or if you should write a class for each level you have? \$\endgroup\$ – bummzack Oct 20 '11 at 7:17

Im not a great Flash programmer, but in general it's always a bad idea to mix data and code.

You should rather try to store your data in external formats like XML and write a class to interface it.

So you basically have one Level-class and your Importer-class which can transform your XML into a level.

I hope you get the basic idea.

  • \$\begingroup\$ +1, exactly what I was going to say. Take a look at Deadly Alien Map Editor for a good example of how you can store level data: dambots.com/dame-editor \$\endgroup\$ – michael.bartnett Oct 20 '11 at 6:19

To add to @Anonymouse's very sensible answer -- if you intend to release it to Flash game portals, it's really important that you do not assume that you can use straight XML files with your final game, i.e. as separate files. The reason is that the portals generally expect to receive one file, your SWF, and nothing else. With AS3, it can then be better simply embed your XML into a class file using the [Embed] tag, and wire things up accordingly. Of course, if you want to keep the XML separate during development, and then put the XML body into a class file at the end, then that's fine too.

Although it sounds counter-intuitive, anyone who has released to the game portals out there will tell you the same. Even if not all of them require this, it is better to aim for the lowest common denominator and get a wider spread without having to have different versions for different portals.

  • \$\begingroup\$ What do you mean by "write your XML into a class file"? You can just use the [Embed] metadata tag to embed assets into the compiled swf. \$\endgroup\$ – bummzack Oct 20 '11 at 8:03
  • \$\begingroup\$ @bummzack Agreed. Corrected. \$\endgroup\$ – Engineer Oct 20 '11 at 8:10
  • \$\begingroup\$ @Nick Wiggill Vaguely related: To get around that limitation, do you think it's feasible then to host your own content swfs and stream those in remotely during play? \$\endgroup\$ – michael.bartnett Oct 20 '11 at 12:09
  • \$\begingroup\$ @bearcdp I don't think you'd find many who'd recommend it. Certainly not for simpler games. But if you're creating something like an MMO with a persistent world, then obviously that would be a nessecity. In general? Avoid unnecessary integrations like plague. \$\endgroup\$ – Engineer Oct 20 '11 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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