Skip to content
Michael Aquilina edited this page May 7, 2013 · 6 revisions

Because maps often contain custom functionality that requires a number of scripts to run consistently and with triggers, TeeEngine provides support for specifying classes to run scripts during the lifetime of a map. These scripts require to implement the IMapScript interface, which provides a number of Hooks that allow for custom functionality to be specified.

IMapScript

  • MapLoaded(TeeEngine engine, TiledMap map, MapEventArgs mapEventArgs): Called when the Map is being loaded into a TeeEngine instance which is passed in the parameters as engine. The TiledMap instance being loaded is also passed in the parameters under map. In order to allow passing of information to maps being loaded, n instance of a MapEventArgs object can also passed with this method which contains information in the form of a dictionary with string key/value pairs (this is because MapEventArgs inherits from the PropertyBag class found in the GameObjects namespace).

  • Update(TeeEngine engine, GameTime gameTime): Called by the game engine at the beginning of each Update loop - before any Update calls to other entities loaded have been made. The Update routine allows very powerful manipulation of the current game state through the use of the TeeEngine instance passed in the parameters as engine.

  • MapUnloaded(TeeEngine engine, TiledMap map): Called when the Map associated with this MapScript is being unloaded in order to be replaced by some other map in the game. An instance of the engine that was making use of this map is passed in the parameters as well as an instance of the map that is being unloaded. This method routine should be used to unload any relevant resources and undo any settings made that were specifically for this map.

Specifying MapScripts in Tiled

In order to make a Tiled make use of an IMapScript class, two properties need to be specified in the Map's properties pane. You can reach the properties pane in Tiled by going to Map->Map Properties in the menu toolbar. Once there, the following properties need to be added:

  • Assembly: The name of the Assembly which contains the class to be used as a Map script.

  • MapScript: The full name of the class that will server as the Map Script. The class specified must implement the IMapScript interface or a runtime error will be thrown. The full name of the class refers to specifying both the namespace and the class name (for example: Some2DRG.MapScripts.ExampleMapScript).

Clone this wiki locally