gpt4 book ai didi

ios - 如何在适用于 iOS 的 Adob​​e AIR 中同时收听点击和手势?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:32:01 24 4
gpt4 key购买 nike

我正在制作一款 iOS 游戏,我需要同时检测简单的点击和手势(滑动等)。在 AIR 中,我只能看到一个用于多点触控输入模式的设置:TOUCH_POINT(适用于基本点击)和 GESTURE。但我同时需要两者,所以改变模式不是一种选择。如何同时收听两者?

谢谢,可以。

最佳答案

import flash.events.EventDispatcher;
import flash.events.TouchEvent;
import flash.net.Responder;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;

public class SwipeAndTap extends EventDispatcher
{
private var fingerX:int;
private var fingerY:int;
private var elem:Object;

public function SwipeAndTap(_elem:Object)
{
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;

elem = _elem;
elem.addEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
elem.addEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
elem.addEventListener(TouchEvent.TOUCH_END, onTouchEnd);
}
private function onTouchBegin(e:TouchEvent):void
{
fingerX = e.stageX;
fingerY = e.stageY;
}
private function onTouchMove(e:TouchEvent):void
{
if(e.stageX > (fingerX+150) && (e.stageY > (fingerY-100) && e.stageY < (fingerY+100) ) )
{
// swipe right
dispatchEvent(new TouchSwipeRight(TouchSwipeRight.SWIPE_RIGHT, e));
}
else if(e.stageX < (fingerX-150) && (e.stageY > (fingerY-100) && e.stageY < (fingerY+100) ) )
{
// swipe left
dispatchEvent(new TouchSwipeLeft(TouchSwipeLeft.SWIPE_LEFT, e));
}
}

private function onTouchEnd(e:TouchEvent):void
{
// e.touchPointID;
if(e.stageX > (fingerX-40) && e.stageX < (fingerX+40))
{
dispatchEvent(new TouchEventTap(TouchEventTap.TAP, e));
elem.removeEventListener(TouchEvent.TOUCH_BEGIN, onTouchBegin);
elem.removeEventListener(TouchEvent.TOUCH_MOVE, onTouchMove);
elem.removeEventListener(TouchEvent.TOUCH_END, onTouchEnd);
}

}
}

例子:

var SAT:SwipeAndTap = new SwipeAndTap(stage);
SAT.addEventListener(TouchEventTap.TAP, LangSelected);
SAT.addEventListener(TouchSwipeRight.SWIPE_RIGHT, ENtoPL);
SAT.addEventListener(TouchSwipeLeft.SWIPE_LEFT, PLtoEN);

关于ios - 如何在适用于 iOS 的 Adob​​e AIR 中同时收听点击和手势?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11769394/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com