Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 如何使我的游戏支持触摸屏?_Actionscript 3_Flash_Actionscript_2d Games - Fatal编程技术网

Actionscript 3 如何使我的游戏支持触摸屏?

Actionscript 3 如何使我的游戏支持触摸屏?,actionscript-3,flash,actionscript,2d-games,Actionscript 3,Flash,Actionscript,2d Games,我已经完成了一个教程中的轮子游戏。问题是,这款游戏可以完美地使用鼠标,但不能在触摸屏上运行。我不知道如何操纵它来改变游戏 如何使游戏适应触摸屏的功能 package { import flash.display.Sprite; import flash.display.Shape; import flash.events.MouseEvent; import flash.events.Event; import com.greensock.TweenMa

我已经完成了一个教程中的轮子游戏。问题是,这款游戏可以完美地使用鼠标,但不能在触摸屏上运行。我不知道如何操纵它来改变游戏

如何使游戏适应触摸屏的功能

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;
            }
        }
    }
}
包
{
导入flash.display.Sprite;
导入flash.display.Shape;
导入flash.events.MouseEvent;
导入flash.events.Event;
导入com.greensock.TweenMax;
公共最终类主扩展Sprite
{
专用var速度:数字=0;
专用变量桨:向量。=新向量。();
私有变量线:形状;
私人桨:字符串;
公共最终函数Main():void
{
推动(wheel.p1、wheel.p2、wheel.p3、wheel.p4、wheel.p5、wheel.p6、wheel.p7、wheel.p8、wheel.p9、wheel.p10);
侦听器('add');
}
私有最终函数侦听器(操作:字符串):void
{
如果(操作=='add')
{
stage.addEventListener(MouseEvent.MOUSE_DOWN,startDraw);
stage.addEventListener(MouseEvent.MOUSE_UP,spinWheel);
}
其他的
{
stage.removeEventListener(MouseEvent.MOUSE_DOWN,startDraw);
stage.removeEventListener(MouseEvent.MOUSE_UP,spinWheel);
}
}
私有最终函数startDraw(e:MouseEvent):void
{
直线=新形状();
addChild(行);
line.graphics.moveTo(mouseX,mouseY);
line.graphics.lineStyle(80x0000000.3);
stage.addEventListener(MouseEvent.MOUSE_MOVE,drawine);
}
专用最终功能抽绳(e:MouseeEvent):无效
{
line.graphics.lineTo(mouseX,mouseY);
}
专用最终功能旋转轮(e:MouseeEvent):无效
{
stage.removeEventListener(MouseEvent.MOUSE_MOVE,drawine);
监听器(“rm”);
速度=线高度*0.1;
removeChild(行);
行=空;
stage.addEventListener(Event.ENTER_FRAME,spin);
}
私人最终功能旋转(e:事件):无效
{
/*转轮*/
车轮旋转Z+=速度;
/*检测值*/
对于(变量i:int=0;i<10;i++)
{
if(indicator.hArea.hitTestObject(拨片[i]))
{
LASTPABLE=桨[i]。名称;
}
}
/*减速*/
速度-=0.1;
/*当车轮停止时,移除侦听器并重置速度*/

如果(速度首先设置在阶段:

Multitouch.inputMode=MultitouchinInputMode.TOUCH\u点

之后 只需将MouseEvent替换为TouchEvent,将MouseEvent替换为TouchEvent,并将MOUSE\u DOWN替换为TOUCH\u BEGIN和BEGIN 将鼠标悬停到触摸端。之后,必须将事件处理程序中的MouseeEvent更改为TouchEvent 如果你用鼠标移动,那就用鼠标移动

  private final function listeners(action:String):void
    {
        if(action == 'add')
        {
            stage.addEventListener(TouchEvent.TOUCH_BEGIN, startDraw);
            stage.addEventListener(TouchEvent.TOUCH_END, spinWheel);
        }
        else
        {
            stage.removeEventListener(TouchEvent.TOUCH_END, startDraw);
            stage.removeEventListener(TouchEvent.TOUCH_BEGIN, spinWheel);
        }
    }

首先,准备阶段:

Multitouch.inputMode=MultitouchinInputMode.TOUCH\u点

之后 只需将MouseEvent替换为TouchEvent,将MouseEvent替换为TouchEvent,并将MOUSE\u DOWN替换为TOUCH\u BEGIN和BEGIN 将鼠标悬停到触摸端。之后,必须将事件处理程序中的MouseeEvent更改为TouchEvent 如果你用鼠标移动,那就用鼠标移动

  private final function listeners(action:String):void
    {
        if(action == 'add')
        {
            stage.addEventListener(TouchEvent.TOUCH_BEGIN, startDraw);
            stage.addEventListener(TouchEvent.TOUCH_END, spinWheel);
        }
        else
        {
            stage.removeEventListener(TouchEvent.TOUCH_END, startDraw);
            stage.removeEventListener(TouchEvent.TOUCH_BEGIN, spinWheel);
        }
    }
Multitouch.inputMode=MultitouchInputMode.NONE;将应用程序呈现为将触摸读取为鼠标输入:Multitouch.inputMode=MultitouchInputMode.NONE;将应用程序呈现为将触摸读取为鼠标输入: