Skip to content

Commit d9c2fb9

Browse files
author
obiot
committed
Revert "rewrote these two functions with better self-caching"
This reverts commit 40248f1.
1 parent cae8aff commit d9c2fb9

File tree

1 file changed

+19
-23
lines changed

1 file changed

+19
-23
lines changed

src/level/TMXTileset.js

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@
143143
// tile properties
144144
// (collidable, etc..)
145145
this.TileProperties = [];
146-
146+
147+
// a cache for offset value
148+
this.tileXOffset = [];
149+
this.tileYOffset = [];
150+
147151
if (!this.image) {
148152
console.log("melonJS: '" + imagesrc + "' file for tileset '" + this.name + "' not found!");
149153
} else {
@@ -256,33 +260,25 @@
256260
/**
257261
* return the x offset of the specified tile in the tileset image
258262
* @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+
},
271270

272271
/**
273272
* return the y offset of the specified tile in the tileset image
274273
* @private
275274
*/
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+
286282

287283
// draw the x,y tile
288284
drawTile : function(context, dx, dy, tmxTile) {

0 commit comments

Comments
 (0)