我今年只学习AS3,我需要能够将我的关键事件转换为触摸并拖动事件以将我的游戏导出到iOS我的应用程序中的一切工作正常,除了我需要能够的桨水平触摸和拖动。这里有任何帮助,我的代码是桨键事件。
private function keyDownHandler(evt:KeyboardEvent)
{
if (evt.keyCode == Keyboard.A)
{
//1st Player Left Key
p1speed = -1;
}
else if (evt.keyCode == Keyboard.D)
{
//1st Player Right Key
p1speed = 1;
}
if (evt.keyCode == Keyboard.SPACE)
{
spacePressed = true;
}
}
private function keyUpHandler(evt:KeyboardEvent)
{
if ((evt.keyCode == Keyboard.A) || (evt.keyCode == Keyboard.D))
{
p1speed = 0;
}
}
答案 0 :(得分:0)
如果您想使用触摸和拖动事件,则必须实现以下代码:
import flash.ui.Multitouch;
import flash.events.TouchEvent;
import flash.ui.MultitouchInputMode;
然后在您的MainFunction中声明您的变量,您将添加这段代码:
//MultiTouch added for touch gestures
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
在构造函数中:
//setup Listeners when btn's touch begin and end
btnUp.addEventListener(TouchEvent.TOUCH_BEGIN, btnUpMouseOver, false, 0, true);
btnUp.addEventListener(TouchEvent.TOUCH_END, btnUpMouseOver, false, 0, true);
控制事件的功能:
private function btnUpMouseOver(e:TouchEvent):void
{
//trace("btnUpRollOver");
if (e.type == TouchEvent.)
{
//Mouse was pressed on this button
btnPressedUp = true;
}
else if(e.type == TouchEvent.TOUCH_END)
{
//Mouse was released
btnPressedUp = false;
}
}
您也可以参考:Adobe Touch EVents