Tutorial
Setting up the Map
To start we need to create a Map object from the Map.js file.
The first two arguments are the dimensions of the map. The Vector2 is the center location of the map. And the next two arguments are the width and height of the individual cells. And finally the last argument is the default texture.
Once the Map is created, you want to make sure that the camera is properly set up around it.
In this case the Camera is centered upon the Map center and shares the same width and height as the Map.
After the Map has been created and the Camera is set up, we finally want to add our MapObjects and Terrains to the Map so that we can use them later.
Here we tell the Map about our Terrains and MapObjects as well as their properties.
Once the Terrains and Objects have been added to the Map all that is left is to set up the selectors.
This API takes advantage of local storage to change between objects and terrain.
Here we set up a couple functions to set the selected MapObject and Terrain
And here we see those functions being attached to some buttons to facilitate the changing through the UI.
Basic Map Controls
Once you have the Map all set up and ready to go, you will want to be able to start editing with it.
The first and most important thing is to have a way to place MapObjects and Terrain. In our example we use the Spacebar to accomplish this.
This call will modify the space currently selected in the editor and will either place an MapObject, change the Terrain, or Delete depending on the Editors current Mode.
To change the current Edit mode you will have to call the respective function.
In Delete Mode you will be able to delete any MapObject, and in Terrain Mode you will be able to place new Terrains.
Once you have these functions set, we want to look at saving and loading the map. The Save and Load features use the Game Engines ResourceMap to save.
Here on our example we save our map as “map1”.
And then we load it later using the same name.
And finally the last of the main basic functions is the ability to turn on and off Edit mode, so that you can test the Map. This will disable the modifySpace function and hide the MapSelector