我从教程中完成了一个轮盘游戏。问题是游戏与鼠标完美配合,但在触摸屏上不起作用。我不知道如何操纵它来改变游戏。
如何使游戏适应触摸屏?
package
{
import flash.display.Sprite;
import flash.display.Shape;
import flash.events.MouseEvent;
import flash.events.Event;
import com.greensock.TweenMax;
public final class Main extends Sprite
{
private var speed:Number = 0;
private var paddles:Vector.<Sprite> = new Vector.<Sprite>();
private var line:Shape;
private var lastPaddle:String;
public final function Main():void
{
paddles.push(wheel.p1, wheel.p2, wheel.p3, wheel.p4, wheel.p5, wheel.p6, wheel.p7, wheel.p8, wheel.p9, wheel.p10);
listeners('add');
}
private final function listeners(action:String):void
{
if(action == 'add')
{
stage.addEventListener(MouseEvent.MOUSE_DOWN, startDraw);
stage.addEventListener(MouseEvent.MOUSE_UP, spinWheel);
}
else
{
stage.removeEventListener(MouseEvent.MOUSE_DOWN, startDraw);
stage.removeEventListener(MouseEvent.MOUSE_UP, spinWheel);
}
}
private final function startDraw(e:MouseEvent):void
{
line = new Shape();
addChild(line);
line.graphics.moveTo(mouseX, mouseY);
line.graphics.lineStyle(8, 0x000000, 0.3);
stage.addEventListener(MouseEvent.MOUSE_MOVE, drawLine);
}
private final function drawLine(e:MouseEvent):void
{
line.graphics.lineTo(mouseX, mouseY);
}
private final function spinWheel(e:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE, drawLine);
listeners('rm');
speed = line.height * 0.1;
removeChild(line);
line = null;
stage.addEventListener(Event.ENTER_FRAME, spin);
}
private final function spin(e:Event):void
{
/* Rotate Wheel */
wheel.rotationZ += speed;
/* Detect Value */
for(var i:int = 0; i < 10; i++)
{
if(indicator.hArea.hitTestObject(paddles[i]))
{
lastPaddle = paddles[i].name;
}
}
/* Decrease speed */
speed -= 0.1;
/* Remove lIstener and reset speed when wheel stops */
if(speed <= 0)
{
stage.removeEventListener(Event.ENTER_FRAME, spin);
speed = 10;
run(lastPaddle);
listeners('add');
}
}
function run(action:String):void
{
switch(action)
{
case 'p1':
myText.text = "text 10";
break;
case 'p2':
myText.text = "text 25";
break;
case 'p3':
myText.text = "text 20";
break;
case 'p4':
myText.text = "text 50";
break;
case 'p5':
myText.text = "text 30";
break;
case 'p6':
myText.text = "text 75";
break;
case 'p7':
myText.text = "text 40";
break;
case 'p8':
myText.text = "text 100";
break;
case 'p9':
myText.text = "text 50";
break;
case 'p10':
myText.text = "text 125";
break;
}
}
}
}
答案 0 :(得分:4)
首先进入阶段:
Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT
之后 只需将MouseEvent替换为TouchEvent,并将MOUSE_DOWN替换为TOUCH_BEGIN和 MOUSE_UP到TOUCH_END。之后,您必须将事件处理程序中的MouseEvent更改为TouchEvent 如果你使用MOUSE_MOVE,那就是TOUCH_MOVE
bluetoothctl