Managing Scene Assets

Hi, I’m curious as how scene assets are typically managed with Corona. For example, my scene may have the following:

A tile grid (1,0,1,0 etc.)

A Hero

A Bad Guy

Each of those items has attributes that I do not want to hard code into a class or take up space on my scene.lua  file. I was thinking this info could be best managed in a json file that would be loaded in when a scene is initialized, but I don’t know if that’s how things are typically done or if there is an easier solution.

Any help is appreciated,

Chris

Hi Chris,

One way to do this is with OOP (object oriented programming). If you are unfimiliar with OOP in Lua, I suggest going through this. http://www.develephant.net/an-rpg-themed-oop-design-pattern-for-corona-sdk-part-1/

Develephant also has a lot of other great corona tutorials and is active here on the forums as well.

Hope this helps!

Eric

Thanks, Eric, but I don’t think I was explaining myself correctly. Let me give it another shot.

Let’s say I have a tile map where each tile has either a 1 or 0 value. 1 means land and 0 means water. That tile map will end up looking like {0,1,1,1,0}, except a lot larger. The map has other values too, like the location of bad guys, hero spawn points, special items, etc.

There can also be lots of maps, each with different tiles, heroes, and bad guys. The code that loads the map and map items will be exactly the same, but the maps themselves will all be different. Would it best to store the data associated with each map as a JSON file named map1, map2, map3…? That way if I ever need to edit something on the map, I just go into the JSON or text file instead of digging around in the code.

Yes. Store the data separately from the code. Or, at least for things like the maps that are big and unwieldily. That gives you the most options in the future (making a separate editor, etc.). 

JSON’s a good format because it’s easy to turn that into a Lua table for use in Corona.

 Jay

Great. Thanks, Jay.

Hi Chris,

One way to do this is with OOP (object oriented programming). If you are unfimiliar with OOP in Lua, I suggest going through this. http://www.develephant.net/an-rpg-themed-oop-design-pattern-for-corona-sdk-part-1/

Develephant also has a lot of other great corona tutorials and is active here on the forums as well.

Hope this helps!

Eric

Thanks, Eric, but I don’t think I was explaining myself correctly. Let me give it another shot.

Let’s say I have a tile map where each tile has either a 1 or 0 value. 1 means land and 0 means water. That tile map will end up looking like {0,1,1,1,0}, except a lot larger. The map has other values too, like the location of bad guys, hero spawn points, special items, etc.

There can also be lots of maps, each with different tiles, heroes, and bad guys. The code that loads the map and map items will be exactly the same, but the maps themselves will all be different. Would it best to store the data associated with each map as a JSON file named map1, map2, map3…? That way if I ever need to edit something on the map, I just go into the JSON or text file instead of digging around in the code.

Yes. Store the data separately from the code. Or, at least for things like the maps that are big and unwieldily. That gives you the most options in the future (making a separate editor, etc.). 

JSON’s a good format because it’s easy to turn that into a Lua table for use in Corona.

 Jay

Great. Thanks, Jay.