地图资源分块

<fla:FlCanvas id="mapCanvas" width="{CountryBattleConst.mapWidth}" height="{CountryBattleConst.mapHeight}">
  <image:KingImage id="smallBg" width="{CountryBattleConst.mapWidth}" height="{CountryBattleConst.mapHeight}" maintainAspectRatio="true" mouseChildren="false" mouseEnabled="false"/>
  <fla:FlCanvas id="bigBgCanvas" width="{CountryBattleConst.mapWidth}" height="{CountryBattleConst.mapHeight}"  mouseChildren="false" mouseEnabled="false"/>
  
  
 </fla:FlCanvas>
 <comp:MapZoomCom id="zoom" right="15" y="86"/>

 

package {
 
  override public function onRegister():void
  {
   super.onRegister();
   teamCellMediator = new CountryBattleTeamCellMediator(teamComp);
   fightImgCellMediator = new CBFightingCellMediator

(fightImgCell);
   
   registerMediator(teamCellMediator);
   registerMediator(fightImgCellMediator);
   
   thisView.smallBg.source =

Services.res_fold+"countryBattle/map/0.jpg";
   mapCanvas.addEventListener

(MouseEvent.MOUSE_DOWN,onMouseDownHandler);
   mapCanvas.addEventListener

(MouseEvent.MOUSE_UP,onMouseLeaveHandle);
   mapCanvas.addEventListener

(MouseEvent.MOUSE_MOVE,onMouseOverHandler);
   mapCanvas.addEventListener

(MouseEvent.MOUSE_OUT,onMouseOutrHandler);
   mapCanvas.addEventListener(MouseEvent.CLICK  ,

onClickHandle );
   preLoaderResAry.push(Services.res_fold+"uiSwf/CBattleUI.swf");
   preLoaderResAry.push

(Services.res_fold+"countryBattle/effect/shapeZoom.swf");
  }
  
  
  protected function onMouseOverHandler(event:MouseEvent):void
  {
   var mapX:int =event.stageX- mapCanvas.x;
   var mapY:int = event.stageY- mapCanvas.y;
   
   KingToolTipManager.getInstance().showToolTip("X:"+mapX+" 

Y:"+mapY);
  }  
  protected function onMouseOutrHandler(event:MouseEvent):void
  {
   KingToolTipManager.getInstance().destroy();
  }  
  
  /** * 外部调用 显示地图*/  
  public function showMap(show:Boolean=false):void
  {
   if(!show){
    thisView.visible = false;
    if(Application.application.hasEventListener

(ResizeEvent.RESIZE))
     Application.application.removeEventListener

(ResizeEvent.RESIZE,app_application_resize_handle);
   }else{
    if(!haveLoaderUIRes){
     preLoaderFunc();
    }else{
     compInit();
     thisView.visible = true;
     if(!Application.application.hasEventListener

(ResizeEvent.RESIZE))
      

Application.application.addEventListener

(ResizeEvent.RESIZE,app_application_resize_handle);
    }
   }
  }
  
  
  private  var preLoaderResAry:Array = [];
  /**是否加载过资源**/
  private var haveLoaderUIRes:Boolean = false;
  
  private function preLoaderFunc():void
  {
   var mutltLoadData:ILoadMultSourceData =

ResourceManager.getInstance().getMultLoadSourceData();
   for each(var resUrl:String in preLoaderResAry){
    var resType:String = StringTWLUtil.getURLType(resUrl);
    switch(resType.toLocaleLowerCase()){
     case "swf":
      mutltLoadData.addSWFData

(ResourceManager.getInstance().getLoadSourceData(resUrl));
      break;
     case "png":
     case "jpg":
      mutltLoadData.addImgData

(ResourceManager.getInstance().getLoadSourceData(resUrl));
      break;
    }
   }
   
   var dt:ILoadQueueDataProxy =  ResourceManager.getInstance

().getLoadQueueDataProxy();
   dt.multSourceData   = mutltLoadData;
   dt.forceShowErrorMsgBool = true
   dt.allLoadComplete_f  = preloadSourceComplete;
   dt.loadProgressF  = preloadSourceProgress;
   dt.threadNum    = 1;
   ResourceManager.getInstance().loadMultResource(dt); 
  }
  
  private function preloadSourceProgress(evt:LoadQueueEvent=null):void
  {
   var percent:Number = evt.getLoadTotalProgress();
   sendAppNotification("loadingProgressEvent", {text:"加载国战ui"+

percent + "%", percent:percent/100});
  }
  
  private function preloadSourceComplete(evt:LoadQueueEvent=null):void
  {
   sendAppNotification("loadingCompleteEvent");
   ResourceManager.getInstance().disposeCompeteLoad();
   haveLoaderUIRes = true;
   showMap(true);
  }
  public function app_application_resize_handle(e:ResizeEvent):void
  {
   zoom.resetScreen(mapCanvas.x,mapCanvas.y);
  }
  
  public function compInit():void
  {
   if(!isInit){
    isInit = true;
    CountryBattleManager.getInstance().operate(1);
   }
  }
  
  /**是否初始化完成**/
  public var isInit:Boolean = false;
  /**
   *需要加载的资源队列
   */  
  public var needLoadResArr:Array=[]
  /**
   *是否是加载资源状态
   */   
  public var loadState:Boolean=false;

  
  public function initBack():void
  {
   var width:Number=StageManager.app_width
   var height:Number=StageManager.app_height
   var row:int=Math.ceil(height/CountryBattleConst.mapCellHeight)
   var col:int=Math.ceil(width/CountryBattleConst.mapCellWidth)
   addResList(row,col)
  }
  /**
   *添加资源队列数据
   * @param row
   * @param col
   *
   */  
  public function addResList

(row:int,col:int,initrow:int=0,initcol:int=0):void
  {
   for(var i:int=initrow;i<=row;i++)
   {
    for(var j:int=initcol;j<=col;j++)
    {
     if(!loadBack[i+"_"+j])
     {
      var vo:LoadResTemplate=new

LoadResTemplate
      

vo.url=Services.res_fold+"countryBattle/map/"+(i*CountryBattleConst.rowCell+j+1)+".jpg"
      vo.x=j*CountryBattleConst.mapCellWidth
      vo.y=i*CountryBattleConst.mapCellHeight
      needLoadResArr.push(vo);
      loadBack[i+"_"+j]=true;
     }
    }
   }
   loadResFunction()
  }
  public function loadResFunction():void
  {
   if(!loadState && needLoadResArr.length>0)
   {
    loadState=true;
    var vo:LoadResTemplate=needLoadResArr[0]
    var img:KingImage=new KingImage
    img.complete_fun=resLoadComplate
    img.ioError_fun=resLoadError
    img.source=vo.url
    img.y=vo.y
    img.x=vo.x
    thisView.bigBgCanvas.addChild(img);
   }
   else
   {
    loadState=false;
   }
  }
  /**
   *当前资源加载完成
   *
   */  
  public function resLoadComplate(e:Event=null):void
  {
   loadCurrentResEnd()
  }
  /**
   *当前资源加载出错
   *
   */  
  public function resLoadError(e:Event=null):void
  {
   loadCurrentResEnd()
  }
  /**
   *当前资源加载结束
   *
   */  
  public function loadCurrentResEnd():void
  {
   loadState=false;
   needLoadResArr.shift()
   loadResFunction()
  }
  private function initDrageArea():Rectangle
  {
   var dragRectangle:Rectangle = new Rectangle();
   var stageW:uint = StageManager.app_width;
   var stageH:uint = StageManager.app_height;
   if(stageW < mapCanvas.width)
   {
    dragRectangle.x = stageW - mapCanvas.width;
    dragRectangle.width = -(stageW - mapCanvas.width);
   }else
   {
    dragRectangle.x = 0;
    dragRectangle.width = 0;
   }
   
   if(stageH < mapCanvas.height)
   {
    dragRectangle.y = stageH - mapCanvas.height;
    dragRectangle.height = -(stageH - mapCanvas.height);
   }else
   {
    dragRectangle.y = 0;
    dragRectangle.height = 0;
   }
   return dragRectangle
  }
  private function onMouseDownHandler(e:MouseEvent):void
  {
   mapCanvas.stage.addEventListener(Event.MOUSE_LEAVE  ,

onMouseLeaveHandle );
   mapCanvas.stage.addEventListener(MouseEvent.MOUSE_UP ,

onDragContentUpHandle);
   var rec:Rectangle = initDrageArea();
   mapCanvas.startDrag(false,rec);
   Mouse.cursor = MouseCursor.HAND;
   mapCanvas.addEventListener(Event.ENTER_FRAME,zoomMove);
  }
  public function zoomMove(e:Event):void
  {
   thisView.zoom.setScreenPosition(mapCanvas.x,mapCanvas.y)
  }
  protected function onDragContentUpHandle(e:MouseEvent=null):void
  {
   mapCanvas.removeEventListener(Event.ENTER_FRAME,zoomMove);
   mapCanvas.stopDrag();
   Mouse.cursor = MouseCursor.AUTO;
   mapCanvas.stage.removeEventListener(Event.MOUSE_LEAVE ,

onMouseLeaveHandle );
   mapCanvas.stage.removeEventListener(MouseEvent.MOUSE_UP ,

onDragContentUpHandle);
   loadbackSource()
  }
  
  
  private function onMouseLeaveHandle(e:Event):void
  {
   onDragContentUpHandle();
  }
  /**
   *已经排进加载队列的资源列表,包含已经加载过的,用来判断是否加载该资源
   */  
  private var loadBack:Array=[]
  /**
   *拖动时产生的新地图场景资源
   *
   */   
  public function loadbackSource():void
  {
   var x:Number=mapCanvas.x
   var y:Number=mapCanvas.y
   if((CountryBattleConst.mapCellHeight+y)<StageManager.app_height

|| (CountryBattleConst.mapCellWidth+x)<StageManager.app_width)
   {
    var row:int=Math.ceil((StageManager.app_height-

(CountryBattleConst.mapCellHeight+y))/CountryBattleConst.mapCellHeight)
    var col:int=Math.ceil((StageManager.app_width-

(CountryBattleConst.mapCellWidth+x))/CountryBattleConst.mapCellWidth)
    var initRow:int=(row-

StageManager.app_height/CountryBattleConst.mapCellHeight)
    var initCol:int=(col-

StageManager.app_width/CountryBattleConst.mapCellWidth)
    initRow=initRow<0 ? 0 : initRow
    initCol=initCol<0 ? 0 : initCol
    addResList(row,col,initRow,initCol)
   }
  }
  
  /**
   *设置当前屏幕的位置
   * @param x
   * @param y
   *
   */  
  public function setCurrentScreenPostion(x:Number,y:Number):void
  {
   x=-x+StageManager.app_width/2//修改
   y=-y+StageManager.app_height/2
   var maxX:Number=-(mapCanvas.width-StageManager.app_width)
   var maxY:Number=-(mapCanvas.height-StageManager.app_height)
   if(x<maxX)
    x=maxX
   else if(x>0)
    x=0
   if(y<maxY)
    y=maxY
   else if(y>0)
    y=0
   mapCanvas.x=x;
   mapCanvas.y=y;
   loadbackSource()
   thisView.zoom.setScreenPosition(mapCanvas.x,mapCanvas.y)
  }
  
  public function showShapeZoomEff(_x:Number,_y:Number):void
  {
   Object(thisView.circleZoomEff.content).drawCircle(_x,_y);
  }
  
  
  
  
 }
}

 

 

zoom

<?xml version="1.0" encoding="utf-8"?>
<base:FlCanvas xmlns:mx="http://www.adobe.com/2006/mxml"
      width="{CountryBattleConst.mapZoomW}" height="{CountryBattleConst.mapZoomH}"  clipContent="false"  horizontalScrollPolicy="off" verticalScrollPolicy="off"
      xmlns:base="com.sandy.component.base.*"
      xmlns:image="com.king.component.image.*"
      xmlns:text="com.king.component.text.*"
      >
 <mx:Script>
  <![CDATA[
   import com.king.component.image.KingImage;
   import com.king.model.template.GameDataManager;
   import com.king.modules.countryBattle.CountryBattleConst;
   import com.king.modules.countryBattle.data.CBBuildTpl;
   import com.king.modules.countryBattle.view.CountryBattleContainerMediator;
   import com.king.services.Services;
   import com.sandy.manager.StageManager;
   private var cityArr:Array
   public function initData():void
   {
    cityArr = GameDataManager.CBBuild_TPL_DATA.getAllTpl();
    backImg.asssets = "CBattleUI_mapZoom_bg_a"
    loadRes()
    currentScreen.graphics.lineStyle(0,0xff0000)
    currentScreen.graphics.drawRect(0,0,(CountryBattleConst.mapZoomW/CountryBattleConst.mapWidth)*StageManager.app_width,(CountryBattleConst.mapZoomH/CountryBattleConst.mapHeight)*StageManager.app_height)
   }
   //加载的个数
   public var loadCount:int=0
   
   public function loadRes():void
   {
    if(loadCount<cityArr.length)
    {
     var tpl:CBBuildTpl=CBBuildTpl(cityArr[loadCount])
     loadCount++
     var img:KingImage=new KingImage
     img.source=Services.res_fold+"countryBattle/zoom/"+tpl.curCountryId+".png"
     img.mouseEnabled=false;
     img.mouseChildren=false;
     img.complete_fun=loadResult
     img.ioError_fun=loadResult
     img.x=tpl.x*(CountryBattleConst.mapZoomW/CountryBattleConst.mapWidth)
     img.y=tpl.y*(CountryBattleConst.mapZoomH/CountryBattleConst.mapHeight)
     //img.name="mini"+e.row+"_"+e.col
     addChild(img);
    }
   }
   public function loadResult():void
   {
    loadRes()
   }
   public function resetScreen(screenX:Number,screenY:Number):void
   {
    currentScreen.graphics.clear()
    currentScreen.graphics.lineStyle(0,0xff0000)
    currentScreen.graphics.drawRect(0,0,(CountryBattleConst.mapZoomW/CountryBattleConst.mapWidth)*StageManager.app_width,(CountryBattleConst.mapZoomH/CountryBattleConst.mapHeight)*StageManager.app_height)
    setScreenPosition(screenX,screenY)
   }
   public function setScreenPosition(screenX:Number,screenY:Number):void
   {
    currentScreen.x=Math.floor(Math.abs(screenX)/CountryBattleConst.mapWidth*CountryBattleConst.mapZoomW)
    currentScreen.y=Math.floor(Math.abs(screenY)/CountryBattleConst.mapHeight*CountryBattleConst.mapZoomH)
   }

   protected function clickHandler(event:MouseEvent):void
   {
    var x:Number=event.localX*CountryBattleConst.mapWidth/CountryBattleConst.mapZoomW
    var y:Number=event.localY*CountryBattleConst.mapHeight/CountryBattleConst.mapZoomH
    getCountBattleContainerMediator().setCurrentScreenPostion(x,y)
   }
   public function getCountBattleContainerMediator():CountryBattleContainerMediator
   {
    return iManager.getAppFacade().retrieveMediator(CountryBattleContainerMediator.NAME) as CountryBattleContainerMediator
   }
  ]]>
 </mx:Script>
 
 <image:KingAssetsSource id="backImg" width="185" height="222" mouseChildren="false" mouseEnabled="false" x="-9" y="-52"/>
 <text:KingDefault1Text id="clickCns"  width="{CountryBattleConst.mapZoomW}" height="{CountryBattleConst.mapZoomH}" mouseChildren="false" mouseEnabled="true" click="clickHandler(event)" />
 <mx:UIComponent id="currentScreen" mouseChildren="false" mouseEnabled="false"/>
</base:FlCanvas>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值