赞 | 2 |
VIP | 0 |
好人卡 | 23 |
积分 | 1 |
经验 | 14976 |
最后登录 | 2017-11-7 |
在线时间 | 388 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 55
- 在线时间
- 388 小时
- 注册时间
- 2009-8-4
- 帖子
- 219
|
汪汪 发表于 2016-1-2 18:20
于是......针对副作用,
把高层元件做出半透明遮挡物就好了,
高层元件在显示时在人物下面,
在这个思路基础上想到可以不管tile的分层而是直接多创建一层upperLayer并添加对其的更新,这样似乎兼容性更好一点点
Tilemap.prototype._createLayers = function() { var width = this._width; var height = this._height; var margin = this._margin; var tileCols = Math.ceil(width / this._tileWidth) + 1; var tileRows = Math.ceil(height / this._tileHeight) + 1; var layerWidth = tileCols * this._tileWidth; var layerHeight = tileRows * this._tileHeight; this._lowerBitmap = new Bitmap(layerWidth, layerHeight); this._upperBitmap = new Bitmap(layerWidth, layerHeight); this._layerWidth = layerWidth; this._layerHeight = layerHeight; /* * Z coordinate: * * 0 : Lower tiles * 1 : Lower characters * 3 : Normal characters * 4 : Upper tiles * 5 : Upper characters * 6 : Airship shadow * 7 : Balloon * 8 : Animation * 9 : Destination */ this._lowerLayer = new Sprite(); this._lowerLayer.move(-margin, -margin, width, height); this._lowerLayer.z = 0; this._upperLayer = new Sprite(); this._upperLayer.move(-margin, -margin, width, height); this._upperLayer.z = 4; for (var i = 0; i < 4; i++) { this._lowerLayer.addChild(new Sprite(this._lowerBitmap)); this._upperLayer.addChild(new Sprite(this._upperBitmap)); } this.addChild(this._lowerLayer); this.addChild(this._upperLayer); // 更改原始upperLayer的z值为0,并添加半透明的upperLayerNew this._upperLayer.z = 0; this._upperLayerNew = new Sprite(); this._upperLayerNew.move(-margin, -margin, width, height); this._upperLayerNew.z = 4; this._upperLayerNew.opacity = 200; for (var i = 0; i < 4; i++) { this._upperLayerNew.addChild(new Sprite(this._upperBitmap)); } this.addChild(this._upperLayerNew); }; Tilemap.prototype._updateLayerPositions = function(startX, startY) { var m = this._margin; var ox = Math.floor(this.origin.x); var oy = Math.floor(this.origin.y); var x2 = (ox - m).mod(this._layerWidth); var y2 = (oy - m).mod(this._layerHeight); var w1 = this._layerWidth - x2; var h1 = this._layerHeight - y2; var w2 = this._width - w1; var h2 = this._height - h1; for (var i = 0; i < 2; i++) { var children; if (i === 0) { children = this._lowerLayer.children; } else { children = this._upperLayer.children; } children[0].move(0, 0, w1, h1); children[0].setFrame(x2, y2, w1, h1); children[1].move(w1, 0, w2, h1); children[1].setFrame(0, y2, w2, h1); children[2].move(0, h1, w1, h2); children[2].setFrame(x2, 0, w1, h2); children[3].move(w1, h1, w2, h2); children[3].setFrame(0, 0, w2, h2); } // 增加对upperLayerNew的更新 var children = this._upperLayerNew.children; children[0].move(0, 0, w1, h1); children[0].setFrame(x2, y2, w1, h1); children[1].move(w1, 0, w2, h1); children[1].setFrame(0, y2, w2, h1); children[2].move(0, h1, w1, h2); children[2].setFrame(x2, 0, w1, h2); children[3].move(w1, h1, w2, h2); children[3].setFrame(0, 0, w2, h2); };
Tilemap.prototype._createLayers = function() {
var width = this._width;
var height = this._height;
var margin = this._margin;
var tileCols = Math.ceil(width / this._tileWidth) + 1;
var tileRows = Math.ceil(height / this._tileHeight) + 1;
var layerWidth = tileCols * this._tileWidth;
var layerHeight = tileRows * this._tileHeight;
this._lowerBitmap = new Bitmap(layerWidth, layerHeight);
this._upperBitmap = new Bitmap(layerWidth, layerHeight);
this._layerWidth = layerWidth;
this._layerHeight = layerHeight;
/*
* Z coordinate:
*
* 0 : Lower tiles
* 1 : Lower characters
* 3 : Normal characters
* 4 : Upper tiles
* 5 : Upper characters
* 6 : Airship shadow
* 7 : Balloon
* 8 : Animation
* 9 : Destination
*/
this._lowerLayer = new Sprite();
this._lowerLayer.move(-margin, -margin, width, height);
this._lowerLayer.z = 0;
this._upperLayer = new Sprite();
this._upperLayer.move(-margin, -margin, width, height);
this._upperLayer.z = 4;
for (var i = 0; i < 4; i++) {
this._lowerLayer.addChild(new Sprite(this._lowerBitmap));
this._upperLayer.addChild(new Sprite(this._upperBitmap));
}
this.addChild(this._lowerLayer);
this.addChild(this._upperLayer);
// 更改原始upperLayer的z值为0,并添加半透明的upperLayerNew
this._upperLayer.z = 0;
this._upperLayerNew = new Sprite();
this._upperLayerNew.move(-margin, -margin, width, height);
this._upperLayerNew.z = 4;
this._upperLayerNew.opacity = 200;
for (var i = 0; i < 4; i++) {
this._upperLayerNew.addChild(new Sprite(this._upperBitmap));
}
this.addChild(this._upperLayerNew);
};
Tilemap.prototype._updateLayerPositions = function(startX, startY) {
var m = this._margin;
var ox = Math.floor(this.origin.x);
var oy = Math.floor(this.origin.y);
var x2 = (ox - m).mod(this._layerWidth);
var y2 = (oy - m).mod(this._layerHeight);
var w1 = this._layerWidth - x2;
var h1 = this._layerHeight - y2;
var w2 = this._width - w1;
var h2 = this._height - h1;
for (var i = 0; i < 2; i++) {
var children;
if (i === 0) {
children = this._lowerLayer.children;
} else {
children = this._upperLayer.children;
}
children[0].move(0, 0, w1, h1);
children[0].setFrame(x2, y2, w1, h1);
children[1].move(w1, 0, w2, h1);
children[1].setFrame(0, y2, w2, h1);
children[2].move(0, h1, w1, h2);
children[2].setFrame(x2, 0, w1, h2);
children[3].move(w1, h1, w2, h2);
children[3].setFrame(0, 0, w2, h2);
}
// 增加对upperLayerNew的更新
var children = this._upperLayerNew.children;
children[0].move(0, 0, w1, h1);
children[0].setFrame(x2, y2, w1, h1);
children[1].move(w1, 0, w2, h1);
children[1].setFrame(0, y2, w2, h1);
children[2].move(0, h1, w1, h2);
children[2].setFrame(x2, 0, w1, h2);
children[3].move(w1, h1, w2, h2);
children[3].setFrame(0, 0, w2, h2);
};
|
|