flash8的游戏制作(地图篇)

王朝other·作者佚名  2008-05-19
窄屏简体版  字體: |||超大  举报/纠错

研究flash 8制作mode7模式头大中.......抽空把以前的rpg引擎用flash 8改了下.

下面先介绍下关于地图的制作(本文章适合与对tiles模式了解并对flash8有一定了解的人)

过去制作游戏的时候,经常会为了切割地图而浪费时间.经常会为了地图过大.拖动过于耗机而烦恼.现在这一切都不成问题了.只要你掌握flash8 bitmapdata的基础运用既可.

这次改造后的地图采用导入整张地形图的方式,由as控制切割调用后生成整个map,再由flash切割调用给适当的场景.

效果如下(地图暂时采用随机模式,用方向键可控制地图的滚动.)

下面贴出代码:

importflash.display.BitmapData;

importflash.geom.*;

class_map{

vartimeline:MovieClip;

varmaps:Array;

varbg:MovieClip;

vartileBmd:BitmapData;

varmapBmd:BitmapData;

varbgBmd:BitmapData;

vartileStep:Number;

vartileCount:Number;

vartileRect:Rectangle;

varbgRect:Rectangle;

varwidth:Number;

varheight:Number;

varx:Number;

vary: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;

timeline._y=(Stage.height-height)/2;

bg=timeline.createEmptyMovieClip("bg",0);

this.maps=maps;

//地图tile范围

tileRect=newRectangle(0,0,tileStep,tileStep);

bgRect=newRectangle(0,0,width,height);

//创建地图元素

tileBmd=BitmapData.loadBitmap(linkId);

this.tileStep=tileStep;

tileCount=tileBmd.width/tileStep;

//建立地图

build();

}

functionbuild(){

mapBmd=newBitmapData(maps[0].length*tileStep,maps.length*tileStep,false,0);

for(vary=0;y

for(varx=0;x

attach(0,x*tileStep,y*tileStep);

if(maps[y][x]<>0){

attach(maps[y][x],x*tileStep,y*tileStep);

}

}

}

bgBmd=newBitmapData(width,height,false,0);

bg.attachBitmap(bgBmd,0);

bgBmd.copyPixels(mapBmd,bgBmd.rectangle,newPoint(0,0));

}

functionattach(id:Number,x:Number,y:Number){

varrect:Rectangle=tileRect.clone();

rect.y=Math.floor(id/tileCount)*tileStep;

rect.x=id%tileCount*tileStep;

mapBmd.copyPixels(tileBmd,rect,newPoint(x,y));

}

functionscroll(){

x=x<0?0:(x>(mapBmd.width-width)?(mapBmd.width-width):x);

y=y<0?0:(y>(mapBmd.height-height)?(mapBmd.height-height):y);

bgRect.x=x;

bgRect.y=y;

bgBmd.copyPixels(mapBmd,bgRect,newPoint(0,0));

}

}

总体感觉.效率提高很大.无论画面如何放大,一样能保持流畅的滚动.这个方法不单适用与tiles模式,如果你是整图把地形图转为map的过程省略掉即可.

举报/纠错
 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005-2025 王朝網路 版權所有 聯絡我們導航