mirror of
https://github.com/photonstorm/phaser
synced 2024-11-21 20:23:19 +00:00
The Tileset.updateTileData
method has two new optional parameters offsetX
and offsetY
which allow you to set the offset that the tile data starts from within the base source texture.
This commit is contained in:
parent
724ed7ec17
commit
133073a55e
1 changed files with 16 additions and 7 deletions
|
@ -42,7 +42,7 @@ var Tileset = new Class({
|
|||
if (tileData === undefined) { tileData = {}; }
|
||||
|
||||
/**
|
||||
* The name of the Tileset.
|
||||
* The name of the Tileset.s
|
||||
*
|
||||
* @name Phaser.Tilemaps.Tileset#name
|
||||
* @type {string}
|
||||
|
@ -302,9 +302,13 @@ var Tileset = new Class({
|
|||
{
|
||||
this.image = texture;
|
||||
|
||||
this.glTexture = texture.get().source.glTexture;
|
||||
var frame = texture.get();
|
||||
|
||||
this.updateTileData(this.image.source[0].width, this.image.source[0].height);
|
||||
var bounds = texture.getFrameBounds();
|
||||
|
||||
this.glTexture = frame.source.glTexture;
|
||||
|
||||
this.updateTileData(bounds.width, bounds.height, bounds.x, bounds.y);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
@ -365,11 +369,16 @@ var Tileset = new Class({
|
|||
*
|
||||
* @param {number} imageWidth - The (expected) width of the image to slice.
|
||||
* @param {number} imageHeight - The (expected) height of the image to slice.
|
||||
* @param {number} [offsetX=0] - The x offset in the source texture where the tileset starts.
|
||||
* @param {number} [offsetY=0] - The y offset in the source texture where the tileset starts.
|
||||
*
|
||||
* @return {Phaser.Tilemaps.Tileset} This Tileset object.
|
||||
*/
|
||||
updateTileData: function (imageWidth, imageHeight)
|
||||
updateTileData: function (imageWidth, imageHeight, offsetX, offsetY)
|
||||
{
|
||||
if (offsetX === undefined) { offsetX = 0; }
|
||||
if (offsetY === undefined) { offsetY = 0; }
|
||||
|
||||
var rowCount = (imageHeight - this.tileMargin * 2 + this.tileSpacing) / (this.tileHeight + this.tileSpacing);
|
||||
var colCount = (imageWidth - this.tileMargin * 2 + this.tileSpacing) / (this.tileWidth + this.tileSpacing);
|
||||
|
||||
|
@ -391,8 +400,8 @@ var Tileset = new Class({
|
|||
|
||||
this.texCoordinates.length = 0;
|
||||
|
||||
var tx = this.tileMargin;
|
||||
var ty = this.tileMargin;
|
||||
var tx = this.tileMargin + offsetX;
|
||||
var ty = this.tileMargin + offsetY;
|
||||
|
||||
for (var y = 0; y < this.rows; y++)
|
||||
{
|
||||
|
@ -402,7 +411,7 @@ var Tileset = new Class({
|
|||
tx += this.tileWidth + this.tileSpacing;
|
||||
}
|
||||
|
||||
tx = this.tileMargin;
|
||||
tx = this.tileMargin + offsetX;
|
||||
ty += this.tileHeight + this.tileSpacing;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue