englercj / phaser-tiled

A tilemap implementation for phaser focusing on large complex maps built with the Tiled Editor.
MIT License
290 stars 31 forks source link

Error spacing tilesets #48

Closed nilocesar closed 8 years ago

nilocesar commented 8 years ago

Sorry for my English ... I wonder if there is any solution for when my tilesets have different spacing of 0 ... Because it generates the following error: " Texture Error : frame does not fit inside the base Texture dimensions" .

englercj commented 8 years ago

The spacing property of Tiled Tilesets are supported, is the tileset setup properly in Tiled? Can you show me a broken example?

nilocesar commented 8 years ago

I am using the Phaser 2.3 ....

"tilesets":[ { "columns":12, "firstgid":1, "image":"..\/..\/..\/plataforma3\/assets\/images\/tiles_spritesheet32x32.png", "imageheight":431, "imagewidth":420, "margin":0, "name":"imagem32_32", "spacing":1, "tilecount":156, "tileheight":32, "tilewidth":32 }],

When I put spacing 0 the game run smoothly, with only visual error. However, when I put spacing 1, it generate the error: Error: Texture Error: frame does not fit inside the base dimensions Texture

With error - spacing 1 http://nilocesar.eu/site/plataforma/

With no error - spacing 0 http://nilocesar.eu/games/plataforma04/

nilocesar commented 8 years ago

I found the error:

this.numTiles = this.multiImage ? tileTextures.length : new Phaser.Point( Phaser.Math.floor((this.baseTexture.width - this.margin) / (this.tileWidth - this.spacing)), Phaser.Math.floor((this.baseTexture.height - this.margin) / (this.tileHeight - this.spacing)) );

Replace with:

this.numTiles = this.multiImage ? tileTextures.length : new Phaser.Point( Phaser.Math.floorTo((this.baseTexture.width - this.margin) / (this.tileWidth + this.spacing)), Phaser.Math.floorTo((this.baseTexture.height - this.margin) / (this.tileHeight + this.spacing)) );

englercj commented 8 years ago

This was fixed a long time ago in the v2 branch:

https://github.com/englercj/phaser-tiled/blob/thin-tiles/src/tiled/Tileset.js#L149-L152

:)