Skip to content

Commit

Permalink
More documentation on the Map / TMX stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
obiot committed Mar 23, 2012
1 parent bc0dd00 commit ba9f2a8
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 42 deletions.
4 changes: 3 additions & 1 deletion src/level/TMXTiledMap.js
Expand Up @@ -203,6 +203,8 @@
/**
* a TMX Tile Map Object
* Tile QT 0.7.x format
* @class
* @extends me.TiledLayer
* @memberOf me
* @constructor
*/
Expand Down Expand Up @@ -376,7 +378,7 @@
},

/**
* clear the tile at the specified position from all layers
* clear the tile at the specified position
* @name me.TMXLayer#clearTile
* @public
* @function
Expand Down
36 changes: 26 additions & 10 deletions src/level/TMXTileset.js
Expand Up @@ -17,9 +17,9 @@
/**************************************************/

/**
* manage a group of Tileset
* an object containing all tileset
* @class
* @memberOf me
* @private
* @constructor
*/
me.TMXTilesetGroup = Object.extend({
Expand All @@ -38,7 +38,15 @@
return this.tilesets[i];
},

// return the tileset corresponding to the specified gid
/**
* return the tileset corresponding to the specified id <br>
* will throw an exception if no matching tileset is found
* @name me.TMXTilesetGroup#getTilesetByGid
* @public
* @function
* @param {Integer} gid
* @return {me.TMXTileset} corresponding tileset
*/
getTilesetByGid : function(gid) {
var invalidRange = -1;
// cycle through all tilesets
Expand All @@ -63,12 +71,13 @@
});


/**
* a tileset object
* @memberOf me
* @private
* @constructor
*/
/**
* a TMX Tile Set Object
* @class
* @extends me.Tileset
* @memberOf me
* @constructor
*/
me.TMXTileset = me.Tileset.extend({

// constructor
Expand Down Expand Up @@ -133,7 +142,14 @@
}
},

// check if the gid belongs to the tileset
/**
* return true if the gid belongs to the tileset
* @name me.TMXTileset#contains
* @public
* @function
* @param {Integer} gid
* @return {boolean}
*/
contains : function(gid) {
return (gid >= this.firstgid && gid <= this.lastgid)
}
Expand Down
156 changes: 125 additions & 31 deletions src/level/level.js
Expand Up @@ -19,27 +19,38 @@

/**
* a basic tile object
* @memberOf me
* @private
* @constructor
*/
* @class
* @extends me.Rect
* @memberOf me
* @constructor
* @param {int} x x index of the Tile in the map
* @param {int} y y index of the Tile in the map
* @param {int} w Tile width
* @param {int} h Tile height
* @param {int} tileId tileId>
*/
me.Tile = me.Rect.extend({
/**
* tileId
* @public
* @type int
* @name me.Tile#tileId
*/
tileId : null,

/** @private */
init : function(x, y, w, h, tileId) {
this.parent(new me.Vector2d(x * w, y * h), w, h);

// tileID
this.tileId = tileId;

this.row = x;
this.col = y;
this.tileId = tileId;
}
});

/**
* a Tile Set Object
* @memberOf me
* @private
* @constructor
* @class
* @memberOf me
* @constructor
*/
me.Tileset = Object.extend({
// constructor
Expand Down Expand Up @@ -99,8 +110,25 @@
};
},

// return the assiocated property of the specified tile
// e.g. getTileProperty (gid)
//
// e.g. getTileProperty (gid)
/**
* return the properties of the specified tile <br>
* the function will return an object with the following boolean value :<br>
* - isCollidable<br>
* - isSolid<br>
* - isPlatform<br>
* - isSlope <br>
* - isLeftSlope<br>
* - isRightSlope<br>
* - isLadder<br>
* - isBreakable<br>
* @name me.Tileset#getTileProperties
* @public
* @function
* @param {Integer} tileId
* @return {Object}
*/
getTileProperties: function(tileId) {
return this.TileProperties[tileId];
},
Expand Down Expand Up @@ -245,6 +273,7 @@

/**
* a generic tile based layer object
* @class
* @memberOf me
* @constructor
*/
Expand Down Expand Up @@ -274,9 +303,15 @@
this.xLUT = {};
this.yLUT = {};

// a reference to the tilesets object
/**
* The Layer corresponding Tilesets
* @public
* @type me.TMXTilesetGroup
* @name me.TiledLayer#tilesets
*/
this.tilesets = tilesets;
// link to the first tileset by default

// the default tileset
this.tileset = tilesets?this.tilesets.getTilesetByIndex(0):null;
},

Expand Down Expand Up @@ -307,35 +342,53 @@
}
},

/**
* get the x,y tile
* @private
/**
* Return the TileId of the Tile at the specified position
* @name me.TiledLayer#getTileId
* @public
* @function
* @param {Integer} x x position
* @param {Integer} y y position
* @return {Int} TileId
*/
getTileId : function(x, y) {
//return this.layerData[~~(x / this.tilewidth)][~~(y / this.tileheight)];
var tile = this.layerData[this.xLUT[~~x]][this.yLUT[~~y]];
//xLut = x / this.tilewidth, yLut = y / this.tileheight;
var tile = this.layerData[this.xLUT[x]][this.yLUT[y]];
return tile ? tile.tileId : null;
},

/**
* get the x,y tile
* @private
/**
* Return the Tile object at the specified position
* @name me.TiledLayer#getTile
* @public
* @function
* @param {Integer} x x position
* @param {Integer} y y position
* @return {me.Tile} Tile Object
*/
getTile : function(x, y) {
//xLut = x / this.tilewidth, yLut = y / this.tileheight;
return this.layerData[this.xLUT[x]][this.yLUT[y]];
},

/**
* set the x,y tile
* @private
/**
* Create a new Tile at the specified position
* @name me.TiledLayer#setTile
* @public
* @function
* @param {Integer} x x position
* @param {Integer} y y position
* @param {Integer} tileId tileId
*/
setTile : function(x, y, tileId) {
this.layerData[x][y] = new me.Tile(x, y, this.tilewidth, this.tileheight, tileId);
},

/**
* clear the tile at the specified position
* @name me.TiledLayer#clearTile
* @public
* @function
* @param {Integer} x x position
* @param {Integer} y y position
*/
Expand Down Expand Up @@ -422,19 +475,60 @@
this.pos = new me.Vector2d(x, y);
this.z = 0;

// tilemap name
/**
* name of the tilemap
* @public
* @type String
* @name me.TileMap#name
*/
this.name = null;

// tilemap size
/**
* width of the tilemap in Tile
* @public
* @type Int
* @name me.TileMap#width
*/
this.width = 0;

/**
* height of the tilemap in Tile
* @public
* @type Int
* @name me.TileMap#height
*/
this.height = 0;

// realwidth (in pixels) of the level
/**
* width of the tilemap in pixels
* @public
* @type Int
* @name me.TileMap#realwidth
*/
this.realwidth = -1;

/**
* height of the tilemap in pixels
* @public
* @type Int
* @name me.TileMap#realheight
*/
this.realheight = -1;

// tile size
/**
* Tile width
* @public
* @type Int
* @name me.TileMap#tilewidth
*/
this.tilewidth = 0;

/**
* Tile height
* @public
* @type Int
* @name me.TileMap#tileheight
*/
this.tileheight = 0;

// corresponding tileset for this map
Expand Down

0 comments on commit ba9f2a8

Please sign in to comment.