HTML and CSS Reference
In-Depth Information
Figure 22-5. Autotiles off
Editor
Editor is a special class that contains methods for all editor tools. There are two tools: the brush places a selected tile
on the map, and the cursor scrolls the map and picks objects. In this demo, cursor picking is not used, but you can
override this if action is required. There is also a special case: if you use brush with a surface tile, the object is removed
from the cell.
Recall your coding a serialization algorithm for MapField (see the section “Map Field and Its Serialization to
JSON”). Now, it's time to use the map. The load and save functions store the map in localStorage . For each site, the
domain browser stores a series of key-value objects. Your map is stored under the key mapData :
function Editor(map) { this.map = map; this.tiles = map.tiles }
Editor.prototype = {
selected: null,
modified: false,
brushAt: function(point) {
var x = point.x >> TILE_SIZE_BITS, y = point.y >> TILE_SIZE_BITS;
var tile = this.selected
if (tile) {
if (tile.layer == 0) {
//if tile is surface, delete the object and place the tile
this.map.setSurface(x, y, tile)
this.map.setObject(x, y, this.tiles.defaultObject)
}
 
Search WWH ::




Custom Search