I'm currently working on a 2d physics based plat former, kinda in the style of super meat boy. In super meat boy, you have multiple levels and I want a similar sort of thing but is there a general way of handling creating entities at the start of a level. Since I'm using an entity-component design and using tiled editor to load levels (and even lua script do to some more config/level related logic), how would I handle creating entities?
Currently, I parse my tiled xml map and do something like
if("MovingPlatform"){
createMovingPlatform(mapObject)
}elseif("SomeOtherEntity"){
} //... so on so forth
But this will soon become a really long branch of if statements just to load my entities. Is there a cleaner design pattern or way of doing this. I was thinking to use a map or strings to classes that create that entity like so:
//in constructor of level loader
entityCreatorMap["MovingPlatform"] = MovingPlatformEntityLoader()
//somewhere later creating my entities by parsing xml
entityCreatorMap[mapObject.getName()].create(mapObject)
But that will be lots of lines initialising these kind of objects. Any ideas?