//添加卷屏事件
function strollMap(dirx) {
var mc = this.target._parent;
if (mc._x<=0) {
var t = mc._x-dirx*this.speed;
if (t>0) {
mc._x = 0;
} else if (t<this.target.mapminx) {
mc._x = this.target.mapminx;
} else {
mc._x -= dirx*this.speed;
var t = Math.abs(Math.floor((this.target._parent._x)/Tile.width));
if (dirx == 1) {
this.dispatchEvent({type:"left", value:t});
} else if (dirx == -1) {
this.dispatchEvent({type:"right", value:t});
}
}
}
}
在Game类中
_char.addEventListener("left", Delegate.create(this, moveleft));
_char.addEventListener("right", Delegate.create(this, moveright));
private function moveleft(obj) {
var t = obj.value-1;
if (t != 0) {
var row = t-1;
if (row>=0 && (row+endx+1)<_mapData.width) {
this.removeRow(row);
this.addRow(row+endx+1);
}
}
}
private function moveright(obj) {
var t = obj.value-1;
if (t>=0) {
var row = t;
if (row>=0 && (row+endx)<_mapData.width) {
this.addRow(row);
this.removeRow(row+endx+1);
}
}
}
//绘制指定列
private function addRow(row:Number) {
var w = _mapData.width;
var h = _mapData.height;
var tileW = Tile.width;
var tileH = Tile.height;
for (var i = 0; i<h; i++) {
var name = "t_"+i+"_"+row;
var mc = _target.wholemap.attachMovie("tile", name, i*w+row);
//依据参数来创建区块
mc.instanc