Sawyer Posted March 29, 2016 Share Posted March 29, 2016 I'm creating a game using tilemaps. Every level is designed similarly which contains chests and levers to open gates. I thought it would be a good idea to set up some global objects, such as levelSetup, which passes in the tilemap for that level to reduce the code for each state. levelSetup( ) adds the player, levers and chests, while I also have a globalObjects function which handles collisions and everything else for the player. I've only just realised that I now have some problems with this way about things. The main one being; How could I tell the current level (state) when a specific lever is pulled from the global function so I can open the corresponding gate? Link to comment Share on other sites More sharing options...
drhayes Posted March 29, 2016 Share Posted March 29, 2016 In my game, I create switches in their own object layer in Tiled. Then, in the code that loads and processes the tilemaps (and makes all the layers and stuff) that code iterates through each object creating Switch instances. Each Switch instance "knows" what it controls by looking for named objects. Essentially, any object that has a "name" property can be referenced by a Switch. When the Switch gets invoked, it calls "state.namedEntities[nameFromSwitch].invoke();" to toggle the thing, whatever it is. Portals works the same way: an object layer in Tiled named portals, special code that makes all the Portals, referring to "levelName" and "portalName" (for where the player appears in the next level). MiY4MOTO 1 Link to comment Share on other sites More sharing options...
Sawyer Posted March 29, 2016 Author Share Posted March 29, 2016 Thanks @drhayes, I'll have to rethink my strategy towards this and start building it again from scratch . Clever thinking with the separate Object Layers, I'll give that a try. Link to comment Share on other sites More sharing options...
Recommended Posts