我正在開發一個遊戲,AS3的Adobe AIR針對Android和iOS上,中,你必須在中央的影片剪輯,和兩個按鈕(左和右)應該移動該影片剪輯。我的目標是儘可能平滑地在左/右之間切換:
- 如果玩家正在觸摸左按鈕,則影片剪輯向左移動。如果他將手指從左按鈕上移開,並立即觸摸右按鈕,則影片剪輯將不會移動,直到他再次觸摸右按鈕,影片剪輯向右移動。我試圖實現多點觸控事件,但我似乎有什麼問題,因爲這是我得到的行爲。
- 如果玩家觸摸左鍵按預期的影片剪輯移至左側,他摸了右側的按鈕,影片剪輯停止不如預期,但如果他從左路按鈕移除他的手指,同時保持它的權利按鈕,影片剪輯仍然凍結和不動,它應該然後移動到右邊
這是我使用的代碼:
移動電影剪輯,左/右使用觸摸事件與同時觸摸
leftButtonCreated.addEventListener(TouchEvent.TOUCH_BEGIN,mouseDown);
rightButtonCreated.addEventListener(TouchEvent.TOUCH_BEGIN,mouseDown2);
stage.addChild(leftButtonCreated);
stage.addChild(rightButtonCreated);
function mouseDown(e:TouchEvent):void
{
stage.addEventListener(TouchEvent.TOUCH_END,mouseUp1);
//listen for mouse up on the stage, in case the finger/mouse moved off of the button accidentally when they release.;
addEventListener(Event.ENTER_FRAME,myButtonClick);//while the mouse is down, run the tick function once every frame as per the project frame rate
}
function mouseUp1(e:TouchEvent):void
{
removeEventListener(Event.ENTER_FRAME,myButtonClick);//stop running the tick function every frame now that the mouse is up
stage.removeEventListener(TouchEvent.TOUCH_END,mouseUp1);
}
function mouseDown2(e:TouchEvent):void
{
stage.addEventListener(TouchEvent.TOUCH_END,mouseUp2);
//listen for mouse up on the stage, in case the finger/mouse moved off of the button accidentally when they release.;
addEventListener(Event.ENTER_FRAME,stopDragging);//while the mouse is down, run the tick function once every frame as per the project frame rate
}
function mouseUp2(e:TouchEvent):void
{
removeEventListener(Event.ENTER_FRAME,stopDragging);//stop running the tick function every frame now that the mouse is up
stage.removeEventListener(TouchEvent.TOUCH_END,mouseUp2);
}
function stopDragging(ev2:Event):void
{
if (MC.x <= rightButtonCreated.x)
{
MC.x = MC.x + 10;
}
}
function myButtonClick(ev:Event):void
{
if (MC.x > leftButtonCreated.x)
{
MC.x = MC.x - 10;
}
else
{
}
}
守則最初設置mouseEvents,所以我試圖轉移到觸摸事件,所以我可以解決這個問題,上面的代碼是我得到的。感謝您的時間。
編輯:
而且,我使用下面的代碼:
var leftButtonCreated:leftB= new leftB();
我試圖改變我的代碼,並使用一個U建議,但影片剪輯只是停止移動,並在地方 –
我的兩個按鈕是在圖書館凍結,並鑄造,因爲它顯示在編輯以上。 –
將每個按鈕包裝成一個'MovieClip'。像這樣:'var leftButtonCreated:MovieClip = new MovieClip(); leftButtonCreated.addChild(新LEFTB());''SimpleButton'是九流類,不允許多,除了內置的開/關/懸停框的,它實際上實幹家沒有一個時間表(但幀 - 非常怪異) 。 – Vesper