未名人的flash rpg地图编辑器代码分析(1)

来源:互联网 发布:软件测试知识点汇总 编辑:程序博客网 时间:2024/06/11 20:47

 (1)地图编辑器的创建对话框

    按下创建按钮后,首先要

   newSceneWindow = TitleWindow(PopUpManager.createPopUp(this, NewScene, true));
   //                PopUpManager.bringToFront(newSceneWindow);
    newSceneWindow.addEventListener( MapEditEvent.NEW_SCENE, newScene);  //把按钮ok按下后的事件创好

(2)弹出编辑对话框,把设置的值赋给父application的成员变量

    this.parentApplication.sceneId = this.sceneId.text;
    
    this.parentApplication.mapWidth = this.mapWidthText.text;
    this.parentApplication.mapHeight = this.mapHeightText.text;
    this.parentApplication.tilePixelWidth = this.tileWidthText.text;
    this.parentApplication.tilePixelHeight = this.tileHeightText.text;
    

   (3)最后确定后 ,激发这个MapEditEvent.NEW_SCENE事件

   this.dispatchEvent(new MapEditEvent(MapEditEvent.NEW_SCENE));

 

(4)地图移动

  鼠标右键按下,记录鼠标按下位置

private function hRightMouseDownCanvas(event:MouseEvent):void
   {
    if (this.mapLayer == null) return;
    
    this.rightMouseDowned = true; //鼠标右键按下
    
    //鼠标按下时所在像素点
    this.mousePointOldX = event.stageX;
    this.mousePointOldY = event.stageY;
   
   }

 当移动鼠标的时候,就要开始动作,同时改变各个层的地图坐标

if (this.rightMouseDowned == true) //鼠标右键按下
    {
     //移动地图
     this.mapLayer.x = this.mapLayer.x + event.stageX - this.mousePointOldX;
     this.mapLayer.y = this.mapLayer.y + event.stageY - this.mousePointOldY;
     this.mousePointOldX = event.stageX;
     this.mousePointOldY = event.stageY;
     
     this.gridLayer.x = this.mapLayer.x;
     this.gridLayer.y = this.mapLayer.y;
     this.walkableLayer.x = this.mapLayer.x;
     this.walkableLayer.y = this.mapLayer.y;
     this.buildingLayer.x = this.mapLayer.x;
     this.buildingLayer.y = this.mapLayer.y;
    }

 

原创粉丝点击