Skip to content

tile图块截取时,间距和边距的应用有明显错误,导致地图拼接时无法吻合 #46

@snafour

Description

@snafour

tile.js 第2833行
if (this.images.length > 1) {
_spritesheet = spritesheets[tile.gid - this.firstgid];
var rect = new egret.Rectangle(0 * (this.tilewidth + this._spacing) + this._spacing, 0 * (this.tileheight + this._margin) + this._margin, this.tilewidth, this.tileheight);
}
else {
_spritesheet = spritesheets[0];
var rect = new egret.Rectangle((id % this.horizontalTileCount) * (this.tilewidth + this._spacing) + this._spacing, (Math.floor(id / this.horizontalTileCount)) * (this.tileheight + this._margin) + this._margin, this.tilewidth, this.tileheight);
}
可以看到你算rect的x位置时,代码用的是编号x间距+间距,y位置时则是编号x边距+边距
但实际上无论x还是y,都应该是编号x间距+边距(间距是两个图块直接的距离,边距是所有图块和纹理集边缘的距离),否则除非边距和间距相等,否则排版一定出现问题(结果是拼接出的地图到处都是黑线,无法互相贴合)
应该改成
if (this.images.length > 1) {
_spritesheet = spritesheets[tile.gid - this.firstgid];
var rect = new egret.Rectangle(0 * (this.tilewidth + this._spacing) + this._margin, 0 * (this.tileheight + this._spacing) + this._margin, this.tilewidth, this.tileheight);
}
else {
_spritesheet = spritesheets[0];
var rect = new egret.Rectangle((id % this.horizontalTileCount) * (this.tilewidth + this._spacing) + this._margin, (Math.floor(id / this.horizontalTileCount)) * (this.tileheight + this._spacing) + this._margin, this.tilewidth, this.tileheight);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions