2012-05-28 38 views
0

首先感謝一些英語錯誤。葡萄牙語是我的第一語言(我來自巴西)AS3:Sprite高速路徑後

我試圖在AS3中從頭開始製作太空遊戲,移動船的方式就像在遊戲空中交通負責人一樣。

我在某個時候成功了。但是,當船速非常快時,它就會開始搖晃,而且它不會很平滑和乾淨。

這裏是我做了什麼:http://megaswf.com/s/2437744

由於代碼是非常大的,所以我在引擎收錄粘貼:pastebin.com/1YVZ23WX 我也寫了一些英文文檔。

這是我的第一場比賽,也是我的第一篇文章。我真的希望你們能幫助我。

在此先感謝。

編輯: 由於代碼非常大,我會盡力在此澄清。

當用戶MouseDown和MouseMove將每一個座標傳遞給一個數組時。 當用戶MouseUP將此數組傳遞給修復數組的函數時。

例如:如果兩個座標之間的距離大於5px,則該函數會在兩個座標中間創建一個座標。

如果我把這個功能解決了問題。但是,如果用戶非常緩慢地移動鼠標,它仍然會發生。這也造成了我試圖用該功能解決的問題。因爲當船舶到達一個座標時,兩個座標的距離非常大,大部分線路消失。

我上傳了一個沒有修復數組的函數的版本。 http://megaswf.com/s/2437775

我認爲有2種方式解決這個問題

1嘗試解決噪聲座標2-陣列中摘下那創建兩個點之間的協調,並嘗試解決問題的功能的線路消失。

這裏是2個重要的功能:

此功能推動船

private function mover():void 
    { 
     if (caminhoCoords[0]!=null) // caminhoCoords is the array that contain the path 
     { 

      var angulo:Number = Math.atan2(this.y - caminhoCoords[0][1], this.x - caminhoCoords[0][0]); 
      this.rotation = angulo/(Math.PI/180); 
      this.x = this.x - velocidade * (Math.cos(angulo)); 
      this.y = this.y - velocidade * (Math.sin(angulo)); 

      var testex:Number = Math.abs(this.x - caminhoCoords[0][0]); //test to see the distance between the ship and the position in the array 
      var testey:Number = Math.abs(this.y - caminhoCoords[0][1]); 



      if (testey<=velocidade+2 && testex<=velocidade+2) // if is velocidade+2 close then go to the next coordnate 
      { 
       caminhoCoords.shift(); 
      } 
     } 
    } 

此功能劃清界線:

private function desenhaCaminho():void //draw the black Path 
    { 
     if(caminhoCoords.length>=1) 
     { 
      caminho.graphics.clear(); 
      caminho.graphics.lineStyle(1, 0x000000, 1,true); 
      caminho.graphics.moveTo(caminhoCoords[0][0],caminhoCoords[0][1]); 
      for (var i:int = 1; i < caminhoCoords.length; i++) 
      { 
       caminho.graphics.lineTo(caminhoCoords[i][0], caminhoCoords[i][1]); 
      } 
     }else 
     { 
      caminho.graphics.clear(); 
     } 
    } 

每當船一到達座標取那些座標關閉數組並重新繪製數組。

有沒有更好的方法呢?

+1

我懷疑你會發現有人爲你挖掘數百行代碼。你試圖縮小這個問題的範圍? –

回答

0

我相信,如果您將飛機的註冊點設置爲中心並使用.snapto(path),則會改善該操作。

+0

歡迎來到stackoverflow.com。這篇文章可能會回答這個問題。更多的解釋可能會幫助同行的程序員理解它是如何工作的。 – Daenarys

0

僅從口吃的外觀來看,我猜你需要平滑一點點「線」。它可能會在線路中產生很多噪音,然後轉化爲飛機的旋轉。平滑飛機的旋轉/位置或線路本身。