未名人的flash rpg地圖編輯器代碼分析(1)

 (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;
    }

 

發佈了28 篇原創文章 · 獲贊 0 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章