2011-03-03 27 views
-1

(我不擅長在AS所以請好:))AS3拖ñ下降到一個單獨的對象

我就簡單的Flash遊戲的工作,其中有R 8個小圓圈了一個大圈的一側。我想把這8個小圓圈一個接一個拖到大圓圈。

基本上1板與他們的食物items.Draging他們的食物項目,他盤子。我希望這會給你一個更好的主意。 我已經瞪大眼睛它同樣的事情,但不能得到我想要的東西,:(

請建議我的腳本或方法。

如果有任何鏈接或TUTS請讓我知道我會很感激。

感謝,

注:Kunal。(網絡 - 設計師)

回答

0

該代碼測試和工程類DummyCircle只是畫一個圓圈中心對其g ^實例化後的raphics對象。

private var plate:Sprite; 
private var stage:Stage; 

public function execute(stage:Stage):void 
{ 
    this.stage = stage; 
    // number of pieces around the centered plate 
    const numPieces:int = 8; 
    const plateRadius:int = 50; 
    plate = new DummyCircle(plateRadius); 
    // center plate on the stage 
    plate.x = stage.stageWidth/2; 
    plate.y = stage.stageHeight/2; 
    stage.addChild(plate); 
    // for each piece to be created 
    for (var i:int = 0; i < numPieces; i++) { 
     // instantiate the appropriate sprite, here with a radius argument 
     var piece:Sprite = new DummyCircle(plateRadius/numPieces); 
     // add event listener for dragging 
     piece.addEventListener(MouseEvent.MOUSE_DOWN, mouseListener); 
     piece.addEventListener(MouseEvent.MOUSE_UP, mouseListener); 
     // pieces are in the top left corner of the stage, plate is centered 
     piece.x = 0; 
     piece.y = 0; 
     // a transformation matrix is used for positioning the pieces 
     // get the current matrix 
     var pieceMatrix:Matrix = piece.transform.matrix; 
     // move a bit more than the plate radius on the y axis 
     pieceMatrix.translate(0, -plateRadius * 1.5); 
     // rotate around the origin 
     pieceMatrix.rotate(i * (2 * Math.PI/numPieces)); 
     // move again, this time to our plate 
     pieceMatrix.translate(plate.x, plate.y); 
     // apply the matrix 
     piece.transform.matrix = pieceMatrix; 
     stage.addChild(piece); 
    } 
} 

private function mouseListener(e:MouseEvent):void 
{ 
    if (e.target is Sprite) { 
     var target:Sprite = e.target as Sprite; 
     if (e.type == MouseEvent.MOUSE_UP) { 
      target.stopDrag(); 
      if (target.hitTestObject(plate)) { 
       stage.removeChild(target); 
      } 
     } 
     else if (e.type == MouseEvent.MOUSE_DOWN) { 
      target.startDrag(); 
     } 
    } 
}