From e7c2b6ae9cbc609fae6fb4f060c900a44779426e Mon Sep 17 00:00:00 2001 From: photonstorm Date: Tue, 14 Jan 2014 00:31:58 +0000 Subject: [PATCH] Fixed nearly all of the tilemap examples to use the new tilemap system. --- examples/assets/sprites/budbrain_chick.png | Bin 0 -> 2322 bytes examples/assets/sprites/exocet_spaceman.png | Bin 0 -> 7828 bytes .../sprites/gameboy_seize_color_40x60.png | Bin 0 -> 2831 bytes .../{tmx/unsorted => maps}/desert.json | 0 examples/tilemaps/fill tiles.js | 15 +- examples/tilemaps/mapcollide.js | 48 +++--- examples/tilemaps/paint tiles.js | 15 +- examples/tilemaps/randomise tiles.js | 27 ++-- examples/tilemaps/replace tiles.js | 13 +- examples/tilemaps/shuffle tiles.js | 82 +++++++++++ examples/tilemaps/swap tiles.js | 13 +- src/physics/arcade/ArcadePhysics.js | 7 +- src/tilemap/Tile.js | 25 +++- src/tilemap/Tilemap.js | 139 +++++++++++------- src/tilemap/TilemapLayer.js | 2 +- src/tilemap/TilemapParser.js | 4 +- 16 files changed, 254 insertions(+), 136 deletions(-) create mode 100644 examples/assets/sprites/budbrain_chick.png create mode 100644 examples/assets/sprites/exocet_spaceman.png create mode 100644 examples/assets/sprites/gameboy_seize_color_40x60.png rename examples/assets/tilemaps/{tmx/unsorted => maps}/desert.json (100%) create mode 100644 examples/tilemaps/shuffle tiles.js diff --git a/examples/assets/sprites/budbrain_chick.png b/examples/assets/sprites/budbrain_chick.png new file mode 100644 index 0000000000000000000000000000000000000000..ed7eecffacd01ed2aec7b3af596d912135f36220 GIT binary patch literal 2322 zcmV+t3GMcYP)~ zTF91gE+Hu)DIr&a-NKcyX~8X|1YMwL90&$U@F&TR_?})8uRi2(FaSZw>o)VXZusfg z@A$j@!@F+u_jWE2-X6yv{CWC11SpfW-5elvZ=ch?|7HXI{qKL%cEUL~DaJoZ>nYnNc(zSCa{+_pgCbq{u|A7fw1)nobM|x=-w0wM@ljvvTkX zd{As=)aElG4G;q0*K6FZ))G-y%Op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A{U6x2KMZ+#s3ROQlv zeFqGd*daSb=VKcnR&vY-EWL$w1G;qA47y_B! zo8Qw{c$R7=9E`1|2WXb+I9!X)@eU#Y$~Cc&Iph|<`uei94%EU59GDq&RJ#Y7cA>`*R_8()NG!Ki8tc$LtWT?0sv)FG6<3`^~GO#R_EzL7j7|?zw zD&=-u3WmIQOjr6{w8LR@I-TZW1RqdJY*6x?Tn%dq1TEVUsMH1l1NM0W?y+*8T`hSV ztC=osmI0Q;D^ANrTy45-sNtpso>e2LSpM@GcT?`Ogb_CdM2Tsx0o4kG0>o5r+pdhb z5+Gd8o3^*mhH<+QBV=-QHH{UB9}dK@pWsrLtxIk>V_6w7tWmaHL4T59VzGrCwv`d9 zX#{|{1;NZUZ=Ru|2(!Dt|Jsyze0;oleNY*3D_N>lBMRHDMlf>i!PEs1WH+C!w-M5c zThs}@;=EbYCV(A7~dUYXpZ1Q|&p^7ChLB1ANj$6zh!jko?=~V6acYEt%&u<%7$b{EKMtF z_GhOB7XeoE(N@b6p*h%)qY;Y{&JY_?LC6)$*}(|0AqRvKuQ4kaJ~rfnU<$F9rWqO= zSXqPfEh3W^T}x+%RyN33Q1n85je^rNGg@v1L_jDX1pmh2!Zv!nux8Fvf)Fx=T+^rt z#04ld0O25{05G*i+)it?!}ZCA^Os=I?}x*oOKEgIj!nUrX<*x59xXM(tRGxheKCTl s^mDZ*dMb@Dff5t)mW-EU{$GFr0E~C*)s?_S_W%F@07*qoM6N<$g5rNKk^lez literal 0 HcmV?d00001 diff --git a/examples/assets/sprites/exocet_spaceman.png b/examples/assets/sprites/exocet_spaceman.png new file mode 100644 index 0000000000000000000000000000000000000000..a71662af681aea1ed776a848d8af9d00b7da18ba GIT binary patch literal 7828 zcmV;F9&6!=P)po0}qu+N&6mj7jB`j>v7O8 zbYGmcdi4wa0I<)ls(q>oPoIAEeeo#c^S6K6^XFAn6|EK8HY zyyqL(UMa{3U<51jt#U@n-Gdl7Nwn#aWHstLqv9gl|hs zMz2Sh?XXR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^iA=HjSa3UyiHcl$bd^of!4&XmFVdWj%d4R##A8La5) z)0>DEOm(3UcBwkN%h!ty6ZkZ*ra<=BO*Gf>xV(nFg-xT$ab*>9&(_D2-2v1~k%Prn zu_yz$V(x5ptDIE4X}t2BMqig(sBfzQ6-yP|IpVK3J^3ugC~vi!41j$-zK|;3^p{r@ zd7_>(Mn@f-K`~h+=@7*R&c_t-PE$eC3C5@r6 zLDKSh7>%N3ZF$%N*U~na^BqrS95C2ot@&#}2et6!>6+j8HKLsyx*pKtyX_jzg_?jx z^+4UsCjGL|5~bN2jnp3w~^@2|a8idkzxZFDCsJ4o`Im6Q=yaE(JVIxDA7v}1uy`d ztjz8s4k{)V{gtwxX5(Z}i6Phz`{$1M?&Ool->UW@68e-U-C%Y9gZBIJ&Ht1R3FE&A zuwNOHSQ6aqV`JQEV?`y7@7eYtzG$Icr5PcEgF@L+?!-TZcANu`vXN6pO52A4}q{4S%nvrLBcqmY|m%A>m_7p=x*op-8~=lG022f}5Lf z!~kNXsuFXzT$^*!o1h8===}d*ABrXogsAh1z&=bgkE8&vearray} tiles - The array of tiles to collide against. * @returns {boolean} Returns true if the bodies were separated, otherwise false. */ separateTiles: function (body, tiles) { @@ -1068,7 +1069,6 @@ Phaser.Physics.Arcade.prototype = { return false; } - // if (body.overlapX !== 0) if (body.touching.left || body.touching.right) { body.x -= body.overlapX; @@ -1084,7 +1084,6 @@ Phaser.Physics.Arcade.prototype = { } } - // if (body.overlapY !== 0) if (body.touching.up || body.touching.down) { body.y -= body.overlapY; diff --git a/src/tilemap/Tile.js b/src/tilemap/Tile.js index 8d66a471..d03ce60c 100644 --- a/src/tilemap/Tile.js +++ b/src/tilemap/Tile.js @@ -19,7 +19,7 @@ Phaser.Tile = function (index, x, y, width, height) { /** - * @property {number} index - The index of this tile within the map. + * @property {number} index - The index of this tile within the map data corresponding to the tileset. */ this.index = index; @@ -127,7 +127,7 @@ Phaser.Tile = function (index, x, y, width, height) { this.collisionCallback = null; /** - * @property {boolean} collisionCallback - Tilemap collision callback. + * @property {boolean} collisionCallback - Tilemap collision callback context. * @default */ this.collisionCallbackContext = this; @@ -200,6 +200,27 @@ Phaser.Tile.prototype = { this.collideUp = false; this.collideDown = false; + }, + + /** + * Copies the tile data and properties from the given tile to this tile. + * @method Phaser.Tile#copy + * @param {Phaser.Tile} tile - The tile to copy from. + */ + copy: function (tile) { + + this.index = tile.index; + this.alpha = tile.alpha; + this.properties = tile.properties; + this.collides = tile.collides; + this.collideNone = tile.collideNone; + this.collideUp = tile.collideUp; + this.collideDown = tile.collideDown; + this.collideLeft = tile.collideLeft; + this.collideRight = tile.collideRight; + this.collisionCallback = tile.collisionCallback; + this.collisionCallbackContext = tile.collisionCallbackContext; + } }; diff --git a/src/tilemap/Tilemap.js b/src/tilemap/Tilemap.js index 7f775a71..610887a8 100644 --- a/src/tilemap/Tilemap.js +++ b/src/tilemap/Tilemap.js @@ -153,6 +153,14 @@ Phaser.Tilemap.prototype = { }, + /** + * Adds an image to the map to be used as a tileset. A single map may use multiple tilesets. + * Note that the tileset name can be found in the JSON file exported from Tiled, or in the Tiled editor. + * + * @method Phaser.Tilemap#addTilesetImage + * @param {string} tileset - The name of the tileset as specified in the map data. + * @param {string} [key] - The key of the Phaser.Cache image used for this tileset. If not specified it will look for an image with a key matching the tileset parameter. + */ addTilesetImage: function (tileset, key) { if (typeof key === 'undefined') @@ -275,9 +283,10 @@ Phaser.Tilemap.prototype = { }, /** - * Gets the layer index based on a layer name. + * Gets the layer index based on the layers name. * * @method Phaser.Tileset#getIndex + * @protected * @param {array} location - The local array to search. * @param {string} name - The name of the array element to get. * @return {number} The index of the element in the array, or null if not found. @@ -348,8 +357,6 @@ Phaser.Tilemap.prototype = { }, - // TODO - set collision in an area, REMOVE collision - /** * Sets collision on all tiles in the given layer, except for the IDs of those in the given array. * @@ -489,6 +496,7 @@ Phaser.Tilemap.prototype = { * Internal function. * * @method Phaser.Tileset#calculateFaces + * @protected * @param {number} layer - The layer to operate on. */ calculateFaces: function (layer) { @@ -636,31 +644,60 @@ Phaser.Tilemap.prototype = { /** * Puts a tile of the given index value at the coordinate specified. * @method Phaser.Tilemap#putTile - * @param {number} index - The index of this tile to set. + * @param {Phaser.Tile|number} tile - The index of this tile to set or a Phaser.Tile object. * @param {number} x - X position to place the tile (given in tile units, not pixels) * @param {number} y - Y position to place the tile (given in tile units, not pixels) * @param {number} [layer] - The Tilemap Layer to operate on. */ - putTile: function (index, x, y, layer) { + putTile: function (tile, x, y, layer) { if (typeof layer === "undefined") { layer = this.currentLayer; } if (x >= 0 && x < this.layers[layer].width && y >= 0 && y < this.layers[layer].height) { - this.layers[layer].data[y][x] = index; + if (tile instanceof Phaser.Tile) + { + this.layers[layer].data[y][x].copy(tile); + } + else + { + this.layers[layer].data[y][x].index = index; + } + this.layers[layer].dirty = true; this.calculateFaces(layer); } }, + /** + * Puts a tile into the Tilemap layer. The coordinates are given in pixel values. + * @method Phaser.Tilemap#putTileWorldXY + * @param {Phaser.Tile|number} tile - The index of this tile to set or a Phaser.Tile object. + * @param {number} x - X position to insert the tile (given in pixels) + * @param {number} y - Y position to insert the tile (given in pixels) + * @param {number} tileWidth - The width of the tile in pixels. + * @param {number} tileHeight - The height of the tile in pixels. + * @param {number} [layer] - The Tilemap Layer to operate on. + */ + putTileWorldXY: function (index, x, y, tileWidth, tileHeight, layer) { + + if (typeof layer === "undefined") { layer = this.currentLayer; } + + x = this.game.math.snapToFloor(x, tileWidth) / tileWidth; + y = this.game.math.snapToFloor(y, tileHeight) / tileHeight; + + this.putTile(tile, x, y, layer); + + }, + /** * Gets a tile from the Tilemap Layer. The coordinates are given in tile values. * @method Phaser.Tilemap#getTile * @param {number} x - X position to get the tile from (given in tile units, not pixels) * @param {number} y - Y position to get the tile from (given in tile units, not pixels) * @param {number} [layer] - The Tilemap Layer to operate on. - * @return {number} The index of the tile at the given coordinates. + * @return {Phaser.Tile} The tile at the given coordinates. */ getTile: function (x, y, layer) { @@ -679,7 +716,7 @@ Phaser.Tilemap.prototype = { * @param {number} x - X position to get the tile from (given in pixels) * @param {number} y - Y position to get the tile from (given in pixels) * @param {number} [layer] - The Tilemap Layer to operate on. - * @return {number} The index of the tile at the given coordinates. + * @return {Phaser.Tile} The tile at the given coordinates. */ getTileWorldXY: function (x, y, tileWidth, tileHeight, layer) { @@ -695,32 +732,6 @@ Phaser.Tilemap.prototype = { }, - /** - * Puts a tile into the Tilemap layer. The coordinates are given in pixel values. - * @method Phaser.Tilemap#putTileWorldXY - * @param {number} index - The index of the tile to put into the layer. - * @param {number} x - X position to insert the tile (given in pixels) - * @param {number} y - Y position to insert the tile (given in pixels) - * @param {number} tileWidth - The width of the tile in pixels. - * @param {number} tileHeight - The height of the tile in pixels. - * @param {number} [layer] - The Tilemap Layer to operate on. - */ - putTileWorldXY: function (index, x, y, tileWidth, tileHeight, layer) { - - if (typeof layer === "undefined") { layer = this.currentLayer; } - - x = this.game.math.snapToFloor(x, tileWidth) / tileWidth; - y = this.game.math.snapToFloor(y, tileHeight) / tileHeight; - - if (x >= 0 && x < this.layers[layer].width && y >= 0 && y < this.layers[layer].height) - { - this.layers[layer].data[y][x] = index; - this.layers[layer].dirty = true; - this.calculateFaces(layer); - } - - }, - /** * Copies all of the tiles in the given rectangular block into the tilemap data buffer. * @method Phaser.Tilemap#copy @@ -774,7 +785,7 @@ Phaser.Tilemap.prototype = { { for (var tx = x; tx < x + width; tx++) { - this._results.push({ x: tx, y: ty, index: this.layers[layer].data[ty][tx] }); + this._results.push(this.layers[layer].data[ty][tx]); } } @@ -807,7 +818,7 @@ Phaser.Tilemap.prototype = { for (var i = 1; i < tileblock.length; i++) { - this.layers[layer].data[ diffY + tileblock[i].y ][ diffX + tileblock[i].x ] = tileblock[i].index; + this.layers[layer].data[ diffY + tileblock[i].y ][ diffX + tileblock[i].x ].copy(tileblock[i]); } this.layers[layer].dirty = true; @@ -827,6 +838,8 @@ Phaser.Tilemap.prototype = { */ swap: function (tileA, tileB, x, y, width, height, layer) { + if (typeof layer === "undefined") { layer = this.currentLayer; } + this.copy(x, y, width, height, layer); if (this._results.length < 2) @@ -839,7 +852,7 @@ Phaser.Tilemap.prototype = { this._results.forEach(this.swapHandler, this); - this.paste(x, y, this._results); + this.paste(x, y, this._results, layer); }, @@ -875,6 +888,8 @@ Phaser.Tilemap.prototype = { */ forEach: function (callback, context, x, y, width, height, layer) { + if (typeof layer === "undefined") { layer = this.currentLayer; } + this.copy(x, y, width, height, layer); if (this._results.length < 2) @@ -884,7 +899,7 @@ Phaser.Tilemap.prototype = { this._results.forEach(callback, context); - this.paste(x, y, this._results); + this.paste(x, y, this._results, layer); }, @@ -901,6 +916,8 @@ Phaser.Tilemap.prototype = { */ replace: function (tileA, tileB, x, y, width, height, layer) { + if (typeof layer === "undefined") { layer = this.currentLayer; } + this.copy(x, y, width, height, layer); if (this._results.length < 2) @@ -916,15 +933,13 @@ Phaser.Tilemap.prototype = { } } - this.paste(x, y, this._results); + this.paste(x, y, this._results, layer); }, /** * Randomises a set of tiles in a given area. * @method Phaser.Tilemap#random - * @param {number} tileA - First tile index. - * @param {number} tileB - Second tile index. * @param {number} x - X position of the top left of the area to operate one, given in tiles, not pixels. * @param {number} y - Y position of the top left of the area to operate one, given in tiles, not pixels. * @param {number} width - The width in tiles of the area to operate on. @@ -946,11 +961,14 @@ Phaser.Tilemap.prototype = { for (var t = 1; t < this._results.length; t++) { - var idx = this._results[t].index; - - if (indexes.indexOf(idx) === -1) + if (this._results[t].index) { - indexes.push(idx); + var idx = this._results[t].index; + + if (indexes.indexOf(idx) === -1) + { + indexes.push(idx); + } } } @@ -959,15 +977,13 @@ Phaser.Tilemap.prototype = { this._results[i].index = this.game.rnd.pick(indexes); } - this.paste(x, y, this._results); + this.paste(x, y, this._results, layer); }, /** * Shuffles a set of tiles in a given area. It will only randomise the tiles in that area, so if they're all the same nothing will appear to have changed! * @method Phaser.Tilemap#shuffle - * @param {number} tileA - First tile index. - * @param {number} tileB - Second tile index. * @param {number} x - X position of the top left of the area to operate one, given in tiles, not pixels. * @param {number} y - Y position of the top left of the area to operate one, given in tiles, not pixels. * @param {number} width - The width in tiles of the area to operate on. @@ -985,20 +1001,31 @@ Phaser.Tilemap.prototype = { return; } - var header = this._results.shift(); + var indexes = []; - Phaser.Utils.shuffle(this._results); + for (var t = 1; t < this._results.length; t++) + { + if (this._results[t].index) + { + indexes.push(this._results[t].index); + } + } - this._results.unshift(header); + Phaser.Utils.shuffle(indexes); - this.paste(x, y, this._results); + for (var i = 1; i < this._results.length; i++) + { + this._results[i].index = indexes[i - 1]; + } + + this.paste(x, y, this._results, layer); }, /** - * Fill a block with a specific tile index. + * Fills the given area with the specified tile. * @method Phaser.Tilemap#fill - * @param {number} index - Index of tiles you want to fill with. + * @param {number} index - The index of the tile that the area will be filled with. * @param {number} x - X position of the top left of the area to operate one, given in tiles, not pixels. * @param {number} y - Y position of the top left of the area to operate one, given in tiles, not pixels. * @param {number} width - The width in tiles of the area to operate on. @@ -1007,6 +1034,8 @@ Phaser.Tilemap.prototype = { */ fill: function (index, x, y, width, height, layer) { + if (typeof layer === "undefined") { layer = this.currentLayer; } + this.copy(x, y, width, height, layer); if (this._results.length < 2) @@ -1019,7 +1048,7 @@ Phaser.Tilemap.prototype = { this._results[i].index = index; } - this.paste(x, y, this._results); + this.paste(x, y, this._results, layer); }, diff --git a/src/tilemap/TilemapLayer.js b/src/tilemap/TilemapLayer.js index ab11e245..4ee19367 100644 --- a/src/tilemap/TilemapLayer.js +++ b/src/tilemap/TilemapLayer.js @@ -88,7 +88,7 @@ Phaser.TilemapLayer = function (game, tilemap, index, width, height) { this.cameraOffset = new Phaser.Point(0, 0); /** - * @property {string} tileColor - If no tile set is given the tiles will be rendered as rectangles in this color. Provide in hex or rgb/rgba string format. + * @property {string} tileColor - If no tileset is given the tiles will be rendered as rectangles in this color. Provide in hex or rgb/rgba string format. * @default */ this.tileColor = 'rgb(255, 255, 255)'; diff --git a/src/tilemap/TilemapParser.js b/src/tilemap/TilemapParser.js index b5fb2370..a90a8254 100644 --- a/src/tilemap/TilemapParser.js +++ b/src/tilemap/TilemapParser.js @@ -314,8 +314,8 @@ Phaser.TilemapParser = { newSet.tileProperties = set.tileproperties; } - newSet.rows = set.imageheight / set.tileheight; - newSet.columns = set.imagewidth / set.tilewidth; + newSet.rows = (set.imageheight - set.margin) / (set.tileheight + set.spacing); + newSet.columns = (set.imagewidth - set.margin) / (set.tilewidth + set.spacing); newSet.total = newSet.rows * newSet.columns; tilesets.push(newSet);