Handling Multiple Objects


(Zouhair Elamrani Abou Elassad) #1

Hi guys, i’m supposed to create like a 6 min level of my game, i have to add several objects i was wondering if there is a robust way to do that instead of adding every object in the world, i already worked with Flash CS5 and it was a bit easy adding Movie Clips to the stage, now it’s different with FlashDevelop, Thank You.


(Martí Angelats i Ribera) #2

I don’t think i understood the question.

FlashPunk works with Worlds and Entities. Each lvl is a World and every object is an Entity. You can add an entity in a world using:

world.add(entity);

If you want to generate objects with code you can create new entities (you can extend the class) and add them to a world at any time.

PD: Have a look here for basic information.


(Zouhair Elamrani Abou Elassad) #3

Yes actually what i meant is that i have a lots of assets, level backgrounds, images of rocks, and i have to add them all to my world, i created entities and now every time i want to add it i must use world.add(entity) and sometimes i have to repeat that for the some entity but for different positions, i was wondering if that’s what i should do ?


(Martí Angelats i Ribera) #4

It will depend of the type of game you are making. Thinking about it i think you have 3 options (you can actually mix of them):

  1. Add everyithing manually.
  2. Use a data Array. Basically an Array with all the objects with the data needed.
  3. A usual option is to save the levels in external files and make a “Level” class that extend World and is able to load them. Is even a better system if you have more than a single level. (use of XML is a good exaple)

Personally i like the last one becouse you can use the same code for ANY other level you want to make.

PD: I don’t know if there is any program to make that easier.


(Zouhair Elamrani Abou Elassad) #5

… I appreciate the feed back and i think i’ll like the third option as well, if you have any examples using external files that would be awesome :smile:


(Mike Evmm) #6

Here


(Zouhair Elamrani Abou Elassad) #7

… thanks man :smile:


(Mike Evmm) #8

You’re welcome! If you’ve never used XML before, I’d also recommend going over the basics: http://www.republicofcode.com/tutorials/flash/as3xml/


(Zouhair Elamrani Abou Elassad) #9

I’ll sure do :smiley: