2014-02-26 75 views
0

我對動作還是比較陌生,並且對實施滑動手勢感到困惑了幾天。 我正在製作一個類似於水果忍者的遊戲,用戶在其中滑動傳入的對象,我一直在試圖弄清楚如何在滑動屏幕後讓對象掉下屏幕。動作滑動手勢難度

 import flash.events.Event; 
    import flash.ui.Multitouch; 
    import flash.ui.MultitouchInputMode; 


    //haggis movement 
    stage.addEventListener(Event.ENTER_FRAME, gameloop); 

    function gameloop(e:Event):void { 
     haggis.x=70; 
     if (haggis.x<-130) 
    { 
      haggis.x=1200; 
     } 
    } 

    //Swipe Gesture 

    Multitouch.inputMode = MultitouchInputMode.GESTURE; 
    stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE , onSwipe); 
    function onSwipe (e:TransformGestureEvent):void{ 
    if (e.offsetX == 1) { 
     //User swiped towards right 
     haggis.y += 200; 
    } 
    if (e.offsetX == -1) { 
    //User swiped towards left 
    haggis.y += 200; 
    } 
    if (e.offsetY == 1) { 
    //User swiped towards bottom 
    haggis.y += 200; 
    } 
    if (e.offsetY == -1) { 
    //User swiped towards top 
    haggis.y += 200; 
    } 
    } 


//piper hit by haggis 

piper.addEventListener(Event.ENTER_FRAME, piper_damaged); 
    function piper_damaged(event:Event):void { 
     if (piper.hitTestObject(haggis)) { 
      piper.gotoAndPlay(2); 
        } 

    } 

哈吉斯是由用戶刷卡的對象。

我也想弄清楚如何在掉下屏幕後讓哈吉斯重置回原來的位置,對此感謝任何幫助,謝謝。

回答

0

添加的增​​量在你的遊戲循環到haggis.y,即:

haggis.y ++; 

如果要模擬重力遞增yMomemtum變量並添加到haggis.y;
如果你想讓哈吉斯只在你滑過它時才掉下來,添加一個haggisSwiped:Boolean並在玩家揮動時設置爲true。然後,在你的遊戲循環,檢查:

if (haggisSwiped) { 
    haggis.y ++; 
} 

而且,你在每幀中設置haggis.x 70,並立即檢查它是否小於-130。你知道爲什麼,因爲我不知道。