HTML and CSS Reference
In-Depth Information
As mentioned earlier, afterInit is used for adding new behaviors and modding (modifying). Define abyss if the
other mods didn't do it in their init function:
afterInit: function(game) {
var tiles = game.tiles, sprites = game.sprites
//abyss can be created in a mod!
tiles.add(new SurfaceTile("abyss"));
} }
Binding Sprites to Tiles
After you configure sprites and tiles, you need to bind all sprites to tiles with the same name and create tiles for sprites
that were not used. Because some types of tiles can bind multiple sprites, you will add the bind method in Tile class
and override it later.
All sprites that are not used in the configuration will be added as object tiles by the addUseless method:
Tile.prototype.bind = function(sprites) {
this.sprite = sprites.get(;
if (sprites.hasOwnProperty( {
var sprite = tile.sprite = sprites.get(;
Every time you bind a sprite to a tile, timesUsed will be increased. In the end, sprites that are not used will create
an ObjectTile for themselves:
Sprite.prototype.timesUsed = 0;
SpriteList.prototype.get = function(name) {
if (this.byName.hasOwnProperty(name)) {
var sprite = this.byName[name];
return sprite;
In this example, you use this mechanism to generate object sprites. You assume that all unused object sprites can
be put on top of the surface layer; in practice, this is reasonable only when you have several surface objects and many
other ones:
TileList.prototype.addUseless = function(TileType, sprites) {
var list = sprites.byName;
var names = [];
for (var key in list)
if (list.hasOwnProperty(key) && list[key].timesUsed == 0)
this.addMany(TileType, names);
for (var i=0;i<names.length;i++) {
this.byName[names[i]].sprite = list[names[i]];
Search WWH ::

Custom Search