Using an array for level data [solved]

For questions about using Classic.

Post » Sun Jan 09, 2011 2:54 am

I'd like to make a game with an inbuilt map editor, and I'm trying to decide how to store the level data.

The example I've seen on the forums is to have the array's X and Y values correspond to positions in a tiled grid, with the identity of the object stored as a string. Like this:

http://dl.dropbox.com/u/906550/Construct/mapeditor.cap

...but that's no good for me, because my world will be large and mostly empty, so the array would end up having an unfeasibly large filesize.

So I'm thinking of using a one-dimensional array as a list of all the objects in the world, and saving the actual information about objects as comma-separated values inside the array. (For example, if the object with ID 1 is a standard block tile at X 250, Y 300, then the first entry in the array would equal "block, 250, 300".)

Here's a quick example I made:

http://dl.dropbox.com/u/906550/Construc ... earray.cap

Does this sound like a sensible approach? I've tested it up to about 1500 objects and it seems to run well - small delay when loading, but acceptable. I'd hate to go ahead with this and find out there's a better way, though. :)

(On that note, I'm thinking about trying the same technique with the List Box object, to see if there's any difference in performance.)
B
5
S
2
G
4
Posts: 113
Reputation: 2,101

Post » Sun Jan 09, 2011 4:47 am

you should use ini files instead, it'll allow for an non-finite number of objects to be saved, and it'll work essentially how you'd do it with an array, except you could add extra properties to be saved in easily and it's just an overall better way to do it.

Arrays are faster for operations that need to be preformed rather frequently, but for level data an ini file is much more scalable and easy to use, the loading at the beginning is the only loading that'll be done, so the small improvements gained through an array will be pretty negligible. also, an ini will make life simpler, and you wont have to organise objects by numbers and cryptic coordinates.

viewtopic.php?f=8&t=4328

heres a good tut
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » Sun Jan 09, 2011 5:36 am

Thanks Quazi! I'll do that. :)
B
5
S
2
G
4
Posts: 113
Reputation: 2,101


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest