for (var y = char.ytile-game.halfvisy; y<=char.ytile+game.halfvisy+1; ++y) { for (var x = char.xtile-game.halfvisx; x<=char.xtile+game.halfvisx+1; ++x) { var name = "t_"+y+"_"+x; if(y>=0 and x>=0 and y<=map.length-1 and x<=map[0].length-1){ game[name] = new game["Tile"+map[y][x]](); }else{ game[name] = new game.Tile4(); } game.clip.attachMovie("tile", name, 1+y*100+x*2); game.clip[name]._x = (x*game.tileW); game.clip[name]._y = (y*game.tileH); game.clip[name].gotoAndStop(game[name].frame); } }
既然卷屏的世界已經(jīng)建好了,下面就該讓它真正“卷”動(dòng)起來(lái)了。在為主角計(jì)算出ob.xtile/ob.ytile的值以后,在moveChar函數(shù)的末尾加上如下代碼來(lái)進(jìn)行卷屏: game.clip._x = game.centerx-ob.x; game.clip._y = game.centery-ob.y; if(ob.xstep<ob.x-game.tileW){ var xtile = Math.floor(ob.xstep/game.tileW) + 1; var xnew=xtile+game.halfvisx+1; var xold=xtile-game.halfvisx-1; for (var i = ob.ytile-game.halfvisy-1; i<=ob.ytile+game.halfvisy+1; ++i) { changeTile (xold, i, xnew, i, _root["myMap"+game.currentMap]); } ob.xstep=ob.xstep+game.tileW; } else if(ob.xstep>ob.x){ var xtile = Math.floor(ob.xstep/game.tileW); var xnew=xtile+game.halfvisx+1; var xold=xtile-game.halfvisx-1; for (var i = ob.ytile-game.halfvisy-1; i<=ob.ytile+game.halfvisy+1; ++i) { changeTile (xold, i, xnew, i, _root["myMap"+game.currentMap]); } ob.xstep=ob.xstep-game.tileW; } if(ob.ystep<ob.y-game.tileH){ var ytile = Math.floor(ob.ystep/game.tileH)+1; var ynew=ytile+game.halfvisy+1; var yold=ytile-game.halfvisy-1; for (var i = ob.xtile-game.halfvisx-1; i<=ob.xtile+game.halfvisx+1; ++i) { changeTile (i, yold, i, ynew, _root["myMap"+game.currentMap]); } ob.ystep=ob.ystep+game.tileH; } else if(ob.ystep>ob.y){ var ytile = Math.floor(ob.ystep/game.tileH); var yold=ytile+game.halfvisy+1; var ynew=ytile-game.halfvisy-1; for (var i = ob.xtile-game.halfvisx-1; i<=ob.xtile+game.halfvisx+1; ++i) { changeTile (i, yold, i, ynew, _root["myMap"+game.currentMap]); } ob.ystep=ob.ystep-game.tileH; } return (true);