# Handling hundreds of sprites

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

## Recommended Posts

I am wondering how you would go about handling hundreds of the same sprite that need to be located in different positions. To give you an idea of whats going on suppose I have a 2d level and their are hundreds of coins positioned throughout the level. How would you position them? I was thinking maybe a script that holds all their positions but that would be a pain to write out. Another idea would be to write a function that positions them based on some parameters. What would you do? Thanks in advance!

##### Share on other sites
Create a mapeditor and use it to place the coins..? Position them either with a script or store their positions in the map file?

##### Share on other sites
Ya, I would do a map editor but this is an old project. I suppose that would be the best solution however! Thanks either way! Sometimes just posting the questions makes me realize the answer ha ha.

##### Share on other sites
I use XML. In my map editor, I would output one Coin entity per coin in the level. Typically, it looks like:

  <Entities>    <Entity template='coin' id='coin-1'>      <Property name='Position'>10,40</Property>    </Entity>    <Entity template='coin' id='coin-2'>      <Property name='position'>25,12</Property>    </Entity>...

I place other entities than coins, too, hence the "template" attribute. Templates, in turn, are defined in another file, and the Entity entities inherit and overrite all the properties in the template. Thus, I would have:

  <Templates>    <Template id='coin'>      <Property name='position'>0,0</Property>      <Property name='pickup'>true</Property>      <Property name='sprite'>coin-one</Property>      <Property name='score'>1</Property>      <Property name='sound'>bling</Property>    </Template>...

This allows you to

##### Share on other sites
Not sure if this is what you were asking, but you should have one list of sprites, and another list of objects. Then the image is only loaded once, and you can place it any number of times.

So basically, each object would contain the position of itself, and a pointer to it's sprite.

##### Share on other sites
Nah, I was more asking for what hplus0603 said.. But like I said I kinda found my answer just posting the question. I am writing an editor for the levels now with C#. It isn't going so well unfortunately because I haven't used c# in a couple years. Either way Thanks for the response

In response to hplus0603 what library do you use to parse XML? or are you not parsing into c++?

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 13
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
632927
• Total Posts
3009241
• ### Who's Online (See full list)

There are no registered users currently online

×