fix tiledtile opacity and no display bug (#3124)

* fix tiledTile opacity invalid and rm layer

* change start to __preload in tilemap

* fix _positionForHexAt bug
This commit is contained in:
Knox
2018-08-22 14:49:17 +08:00
committed by pandamicro
parent f5b81db4c2
commit 9877760e98
4 changed files with 36 additions and 60 deletions
+18 -18
View File
@@ -154,36 +154,36 @@ let TiledLayer = cc.Class({
);
},
_positionForHexAt (x, y) {
let xy;
_positionForHexAt (row, col) {
let tileWidth = this._mapTileSize.width;
let tileHeight = this._mapTileSize.height;
let cols = this._layerSize.height;
let offset = this._tileset.tileOffset;
let centerWidth = this.node.width / 2;
let centerHeight = this.node.height / 2;
let odd_even = (this._staggerIndex === cc.TiledMap.StaggerIndex.STAGGERINDEX_ODD) ? 1 : -1;
let x = 0, y = 0;
switch (this._staggerAxis) {
case cc.TiledMap.StaggerAxis.STAGGERAXIS_Y:
let diffX = 0;
if (y % 2 === 1)
{
diffX = this._mapTileSize.width/2 * odd_even;
let diffX1 = (this._staggerIndex === cc.TiledMap.StaggerIndex.STAGGERINDEX_ODD) ? 0 : tileWidth / 2;
if (col % 2 === 1) {
diffX = tileWidth / 2 * odd_even;
}
xy = cc.v2(x * this._mapTileSize.width+diffX+offset.x,
(this._layerSize.height - y - 1) * (this._mapTileSize.height-(this._mapTileSize.height-this._hexSideLength)/2)-offset.y);
x = row * tileWidth + diffX + diffX1 + offset.x - centerWidth;
y = (cols - col - 1) * (tileHeight - (tileHeight - this._hexSideLength) / 2) - offset.y - centerHeight;
break;
case cc.TiledMap.StaggerAxis.STAGGERAXIS_X:
let diffY = 0;
if (x % 2 === 1)
{
diffY = this._mapTileSize.height/2 * -odd_even;
let diffY1 = (this._staggerIndex === cc.TiledMap.StaggerIndex.STAGGERINDEX_ODD) ? tileHeight / 2 : 0;
if (row % 2 === 1) {
diffY = tileHeight / 2 * -odd_even;
}
xy = cc.v2(x * (this._mapTileSize.width-(this._mapTileSize.width-this._hexSideLength)/2)+offset.x,
(this._layerSize.height - y - 1) * this._mapTileSize.height + diffY-offset.y);
break;
default:
xy = cc.v2(0, 0);
x = row * (tileWidth - (tileWidth - this._hexSideLength) / 2) + offset.x - centerWidth;
y = (cols - col - 1) * tileHeight + diffY + diffY1 - offset.y - centerHeight;
break;
}
return xy;
return cc.v2(x, y);
},
/**
+1 -1
View File
@@ -423,7 +423,7 @@ let TiledMap = cc.Class({
return this._tileProperties[GID];
},
start () {
__preload () {
if (this._tmxFile) {
// refresh layer entities
this._applyFile();
+14 -40
View File
@@ -42,12 +42,14 @@ let TiledTile = cc.Class({
menu: 'i18n:MAIN_MENU.component.renderers/TiledTile',
},
ctor () {
this._layer = null;
},
properties: {
_x: 0,
_y: 0,
_gid: 0,
_layer: null,
_gid: -1,
/**
* !#en Specify the TiledTile horizontal coordinate,use map tile as the unit.
@@ -109,46 +111,14 @@ let TiledTile = cc.Class({
this._gid = value;
},
type: cc.Integer
},
/**
* !#en Specify which TiledLayer the TiledTile belong to.
* !#zh 指定 TiledTile 属于哪一个 TiledLayer
* @property {TiledLayer} layer
*/
layer: {
type: cc.TiledLayer,
get () {
return this._layer;
},
set (value) {
if (value === this._layer) return;
this._resetTile();
this._layer = value;
this._updateInfo();
}
}
},
onEnable () {
if (CC_EDITOR) {
let parent = this.node.parent;
if (!this._layer && !(parent instanceof cc.Scene)) {
this._layer = parent.getComponent(cc.TiledLayer);
this._updateInfo();
}
}
else if (this._layer) {
let tile = this._layer.getTiledTileAt(this._x, this._y);
if (tile) {
if (tile !== this) {
cc.warn('There is already a TiledTile at [%s, %s]', this._x, this._x);
}
}
else {
this._layer.setTiledTileAt(this._x, this._y, this);
}
}
let parent = this.node.parent;
this._layer = parent.getComponent(cc.TiledLayer);
this._resetTile();
this._updateInfo();
},
onDisable () {
@@ -171,7 +141,11 @@ let TiledTile = cc.Class({
}
this.node.setPosition(this._layer.getPositionAt(x, y));
this._gid = this._layer.getTileGIDAt(x, y);
if (this._gid === -1) {
this._gid = this._layer.getTileGIDAt(x, y);
}
this._layer.setTiledTileAt(x, y, this);
},
});
+3 -1
View File
@@ -104,6 +104,7 @@ let tmxAssembler = {
let renderData = comp._renderData;
let data = renderData._data;
let color = node._color._val;
let opacity = node._color.a;
renderData.dataLength = renderData.vertexCount = renderData.indiceCount = 0;
@@ -254,7 +255,8 @@ let tmxAssembler = {
// color
color2 = color;
color = tiledNode.color._val;
let newOpacity = (tiledNode.opacity * opacity) / 255;
color = tiledNode.color.setA(newOpacity)._val;
// transform
a2 = a; b2 = b; c2 = c; d2 = d; tx2 = tx; ty2 = ty;