研究flash 8制作mode7模式头大中.......抽空把以前的rpg引擎用flash 8改了下.
下面先介绍下关于地图的制作(本文章适合与对tiles模式了解并对flash8有一定了解的人) 网管联盟bitsCN@com
过去制作游戏的时候,经常会为了切割地图而浪费时间.经常会为了地图过大.拖动过于耗机而烦恼.现在这一切都不成问题了.只要你掌握flash8 bitmapdata的基础运用既可. 网管bitscn_com
这次改造后的地图采用导入整张地形图的方式,由as控制切割调用后生成整个map,再由flash切割调用给适当的场景.
中国网管联盟bitsCN.com
效果如下(地图暂时采用随机模式,用方向键可控制地图的滚动.)
网管论坛bbs_bitsCN_com
网管联盟bitsCN_com
下面贴出代码:
中国网管论坛bbs.bitsCN.com
import flash.display.BitmapData;
import flash.geom.*;
class _map {
var timeline:MovieClip;
var maps:Array;
var bg:MovieClip;
var tileBmd:BitmapData;
var mapBmd:BitmapData;
var bgBmd:BitmapData;
var tileStep:Number;
var tileCount:Number;
var tileRect:Rectangle;
var bgRect:Rectangle;
var width:Number;
var height:Number;
var x:Number;
var y:Number;
function _map(timeline:MovieClip, linkId:String, maps:Array, tileStep:Number, width:Number, height:Number) {
this.timeline = timeline;
this.width = width;
this.height = height;
this.x = 0;
this.y = 0;
timeline._x = (Stage.width-width)/2; 网管下载dl.bitscn.com
timeline._y = (Stage.height-height)/2;
bg = timeline.createEmptyMovieClip(\"bg\", 0);
this.maps = maps;
//地图tile范围
tileRect = new Rectangle(0, 0, tileStep, tileStep);
bgRect = new Rectangle(0, 0, width, height);
//创建地图元素
tileBmd = BitmapData.loadBitmap(linkId);
this.tileStep = tileStep;
tileCount = tileBmd.width/tileStep;
//建立地图
build();
}
function build() {
mapBmd = new BitmapData(maps[0].length*tileStep, maps.length*tileStep, false, 0);
for (var y = 0; y for (var x = 0; x网管下载dl.bitscn.com
attach(0, x*tileStep, y*tileStep);
if (maps[y][x]<>0) {
attach(maps[y][x], x*tileStep, y*tileStep);
}
}
}
bgBmd = new BitmapData(width, height, false, 0);
bg.attachBitmap(bgBmd, 0);
bgBmd.copyPixels(mapBmd, bgBmd.rectangle, new Point(0, 0));
}
function attach(id:Number, x:Number, y:Number) {
var rect:Rectangle = tileRect.clone();
rect.y = Math.floor(id/tileCount)*tileStep;
rect.x = id%tileCount*tileStep;
mapBmd.copyPixels(tileBmd, rect, new Point(x, y));
}
function scroll() {
x = x<0 ? 0 : (x>(mapBmd.width-width) ? (mapBmd.width-width) : x); 中国网管联盟bitsCN.com
y = y<0 ? 0 : (y>(mapBmd.height-height) ? (mapBmd.height-height) : y);
bgRect.x = x;
bgRect.y = y;
bgBmd.copyPixels(mapBmd, bgRect, new Point(0, 0));
}
}
总体感觉.效率提高很大.无论画面如何放大,一样能保持流畅的滚动.这个方法不单适用与tiles模式,如果你是整图把地形图转为map的过程省略掉即可.
【转自www.bitsCN.com】http://www.bitscn.com/school/Flash/skill/200609/59446.html