@Ignatz @yojimbo2000 I’m currently working on a roguelike 8bit open-world rpg. I decided not to generate my maps but rather design them by hand. Therefore I need to create a map editor. My question is somewhat similar to @Slashin8r in his thread: https://codea.io/talk/discussion/3058/utility-rpgenerator-v0-7-23-build-your-own-rpg-in-codea/p1
What I currently do
- Editor gets one tilesheet (128x128px)
- Each tile on spritesheet is 8x8px
- Each tile can have a flag (similar to PICO-8). It’s really just a number which can be interpreted as anything (for example as a layer name)
The coloured circles are sprite flags for the current sprite.
Each one can be true (on) or false (off).
They are indexed from 0, from the left (0,1,2,4,8,16,32…).
The initial state of flag are settable in the sprite editor, using the line of little colourful buttons.
The meaning of sprite flags is up to the user, or can be used to indicate which group (‘layer’) of sprites should be drawn by map.
For my game I assume that the world has regular tiles (floor, wall, water, lava) and special placeholder tiles (enemy, player, guard, treasure, light source,…) which will be replaced by the engine at runtime with real interactive objects. These objects have states, animations and actions (attack, breath, idle around, protect sth., etc). Plus the world is drawn in layers (one layer per ground, walls, obstacles, players, etc).
Right now the editor saves drawn tiles into projectData like `saveProjectData(“x y flag”, spriteIndex)
When I start my game, the editor does some work for me. It calculates which tiles should be on screen and loads them in. Then it setups these tiles for me - initially, each tile as an object on its own (internally its a class with a mesh and one rect, textured by spriteIndex).
Now, I know about my world (as I have drawn it). I know that a have created a “layer” of tiles for enemies, say this layer has the flag number 25! I can now support my editor with a table World{["25"] = Ork,...}
which specifies which “layer” gets setup with which class. And now they automatically have props! I thought that would be very easy to manage… This way each tile can respond easily to touches and draw updates and I can keep the relevant code in the right place.
The issue
My problem is now that the editor is somewhat inefficient at rendering. I mean, I still get 60fps on an iPad Pro, but the memory consumption is way to high (~1.3Mb)! The editor has to draw, say 5 layers, and each of them has ~100 tiles, which in turn are all separate objects (meshes). So to say: I it makes 500 draw calls each frame!
I can not come up with an effective infrastructure for this whole thing. How to store the map efficiently into projectData. How to load and batch the tiles, but still be able to “speak” to each of them. Like, when I batch the ground and wall tiles into one mesh, but the ground has grass and dirt tiles, how could I easily say which sound to play on each? With my current setup, I could just make two classes (Dirt, Grass) and inside the touched method I would fire a sound. Another concern is how to batch, but still have animations and states?