|
143 | 143 | // tile properties |
144 | 144 | // (collidable, etc..) |
145 | 145 | this.TileProperties = []; |
146 | | - |
| 146 | + |
| 147 | + // a cache for offset value |
| 148 | + this.tileXOffset = []; |
| 149 | + this.tileYOffset = []; |
| 150 | + |
147 | 151 | if (!this.image) { |
148 | 152 | console.log("melonJS: '" + imagesrc + "' file for tileset '" + this.name + "' not found!"); |
149 | 153 | } else { |
|
256 | 260 | /** |
257 | 261 | * return the x offset of the specified tile in the tileset image |
258 | 262 | * @private |
259 | | - */ |
260 | | - getTileOffsetX : (function() { |
261 | | - var cache = []; |
262 | | - return function (tileId) { |
263 | | - var cached = cache[tileId]; |
264 | | - if (cached === undefined) { |
265 | | - return (cache[tileId] = this.margin + (this.spacing + this.tilewidth) * (tileId % this.hTileCount)); |
266 | | - } |
267 | | - return cached; |
268 | | - }; |
269 | | - }()), |
270 | | - |
| 263 | + */ |
| 264 | + getTileOffsetX : function(tileId) { |
| 265 | + if (this.tileXOffset[tileId] == null) { |
| 266 | + this.tileXOffset[tileId] = this.margin + (this.spacing + this.tilewidth) * (tileId % this.hTileCount); |
| 267 | + } |
| 268 | + return this.tileXOffset[tileId]; |
| 269 | + }, |
271 | 270 |
|
272 | 271 | /** |
273 | 272 | * return the y offset of the specified tile in the tileset image |
274 | 273 | * @private |
275 | 274 | */ |
276 | | - getTileOffsetY : (function() { |
277 | | - var cache = []; |
278 | | - return function (tileId) { |
279 | | - var cached = cache[tileId]; |
280 | | - if (cached === undefined) { |
281 | | - return (cache[tileId] = this.margin + (this.spacing + this.tileheight) * ~~(tileId / this.hTileCount)); |
282 | | - } |
283 | | - return cached; |
284 | | - }; |
285 | | - }()), |
| 275 | + getTileOffsetY : function(tileId) { |
| 276 | + if (this.tileYOffset[tileId] == null) { |
| 277 | + this.tileYOffset[tileId] = this.margin + (this.spacing + this.tileheight) * ~~(tileId / this.hTileCount); |
| 278 | + } |
| 279 | + return this.tileYOffset[tileId]; |
| 280 | + }, |
| 281 | + |
286 | 282 |
|
287 | 283 | // draw the x,y tile |
288 | 284 | drawTile : function(context, dx, dy, tmxTile) { |
|
0 commit comments