2014-02-21 53 views
0

因此,我有一個名爲hookLine的影片剪輯,它從我的mainEngine類中添加到舞臺上。此空的影片剪輯連接到我的fisherman影片剪輯並曲線到我的playerHook影片剪輯。它的加入並連接到該級,像這樣:HitTest在使用Graphics.lineTo時無法正常工作/ curveTo

在我mainEngine功能循環:

playerHookLine(); 

則函數:

private function playerHookLine():void 
    { 

     //Add hook line to fisherman and playerhook 
     hookLine.graphics.clear(); 
     hookLine.graphics.lineStyle(1); 
     hookLine.graphics.moveTo(fisherman.x, fisherman.y); 
     hookLine.graphics.curveTo(playerHook.x, playerHook.y, mouseX, mouseY); 

    } 

現在我遇到的問題是每當我嘗試則hitTest hookLine與一個名爲currentShark的移動剪輯hitTest的作品,我得到了一個痕跡,但它不準確的時候,我彎曲我的鉤線兩側和currentShark在舞臺上它自動hitTests並給出我的痕跡。所以基本上鯊魚甚至不必接觸實際的線條圖形。正當鯊魚加入舞臺時,它只是登記。

有沒有人有任何想法,爲什麼這是?

這裏是則hitTest功能是如何:

private function checkPlayerHitShark():void 
    { 
     //Loop through all sharks 
     for (var i:int = 0; i < aSharkArray.length; i++) 
     { 
      //Get current Shark in i loop 
      var currentShark:mcShark = aSharkArray[i]; 

      //Check if shark is hittest with Hook 
      if (currentShark.hitTestObject(playerHook) || currentShark.hitTestObject(hookLine)) 
      { 
       trace("Hook Hit Shark"); 
       trace("hit LINE"); 
       removePlayerLive(); 

       //Destroy player 
       playerHook.destroyPlayerHook(); 
       hookLine.destroyHookLine(); 

       //Remove shark from array 
       aSharkArray.splice(i, 1); 

       //Add new Hook to stage 
       stage.addChild(playerHook); 
       stage.addChild(hookLine); 
      } 


     } 

    } 

回答

1

更可能的是你的鯊魚和魚線的邊框進行碰撞。當您的弧形釣魚線向左或向右移動時,您的邊界框將與釣魚線本身的寬度和高度相同。打開您的項目併發布爲SWF,然後在Flash播放器中打開SWF,然後按Control + E或點擊窗口頂部的視圖並選擇「顯示重繪區域」。你應該看到邊界框呈紅色,因爲它們正在重新繪製到舞臺上。

你正在尋找的是你的鯊魚和釣魚線位圖像素級命中檢測。 BitmapData有一個名爲hitTest的方法,它需要幾個參數。

您打算從在此間鏈接麥克·錢伯斯寫的一篇文章找到像素級的點擊檢測極好的幫助: http://www.mikechambers.com/blog/2009/06/24/using-bitmapdata-hittest-for-collision-detection/

爲BitmapData.hitTest的文檔可以在這裏找到: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html

只需查看公共方法的列表。

+1

我的意思是說,將您的程序發佈爲.SWF文件並在Flash播放器中打開它。玩家本身將在頂部有一個菜單,您將看到「查看」按鈕,在該菜單中顯示重繪區域。我也要編輯我的帖子。 – E10

+0

謝謝你的所有信息。對此,我真的非常感激。你也是對的,無論我移動它,線條都有一個巨大的矩形框。 – Nathan

+0

哦,好吧,我明白了。我會繼續閱讀你現在寄給我的那些文章。那麼生病就能把這個區域縮小到hookLine? – Nathan