Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.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 在as3中向不同方向射击_Actionscript 3 - Fatal编程技术网

Actionscript 3 在as3中向不同方向射击

Actionscript 3 在as3中向不同方向射击,actionscript-3,Actionscript 3,我正在做的游戏有些麻烦。我的角色射出子弹,但当涉及到向不同方向射出子弹时,它不能正常工作。当它射击时,子弹跟随角色的方向。下面我发布代码 var Bulli:Array = new Array(); var ShootTimer:Timer = new Timer(0); stage.addEventListener(MouseEvent.MOUSE_DOWN, startShootTimer); stage.addEventListener(MouseEvent.MOUSE_UP, stopS

我正在做的游戏有些麻烦。我的角色射出子弹,但当涉及到向不同方向射出子弹时,它不能正常工作。当它射击时,子弹跟随角色的方向。下面我发布代码

var Bulli:Array = new Array();
var ShootTimer:Timer = new Timer(0);
stage.addEventListener(MouseEvent.MOUSE_DOWN, startShootTimer);
stage.addEventListener(MouseEvent.MOUSE_UP, stopShootTimer);
ShootTimer.addEventListener(TimerEvent.TIMER, shootBullo);
stage.addEventListener(Event.ENTER_FRAME, mainLoop);

function startShootTimer(e:MouseEvent):void
{
    ShootTimer.start();
}
function stopShootTimer(e:MouseEvent):void
{
    ShootTimer.stop();
}       
function shootBullo(e:TimerEvent):void
{
    var bullo:Bullo = new Bullo();
    bullo.x = Jumbo.x;
    bullo.y = Jumbo.y - 50; 

    if(destra)
    {
        bullo.dir = destra;
    }
    else
    {
        bullo.dir = sinistra;
    }

    addChild(bullo);
    Bulli.push(bullo);
}       
function mainLoop (e:Event):void
{
    for (var b:int = 0; b < Bulli.length; b++)
    {
        if (Bulli[b].dir == destra)
        {
            Bulli[b].x += 10;
        }
        else
        {
            Bulli[b].x -= 10;
        }

    }
}
var Bulli:Array=new Array();
var SHOTETIMER:定时器=新定时器(0);
stage.addEventListener(MouseEvent.MOUSE_DOWN,startShootTimer);
stage.addEventListener(MouseEvent.MOUSE_UP,stopShootTimer);
ShootTimer.addEventListener(TimerEvent.TIMER,shootBullo);
stage.addEventListener(Event.ENTER_FRAME,mainLoop);
函数startShootTimer(e:MouseeEvent):无效
{
ShootTimer.start();
}
函数stopShootTimer(e:MouseEvent):无效
{
ShootTimer.stop();
}       
函数shootBullo(e:TimerEvent):void
{
var bullo:bullo=新的bullo();
bullo.x=Jumbo.x;
bullo.y=Jumbo.y-50;
if(destra)
{
bullo.dir=destra;
}
其他的
{
bullo.dir=左旋;
}
addChild(bullo);
Bulli.push(bullo);
}       
函数mainLoop(e:事件):void
{
for(变量b:int=0;b
不要将该侦听器添加到舞台,而是将其添加到每个独特的
bullo

//# not to Stage...
//stage.addEventListener(Event.ENTER_FRAME, mainLoop);
尝试以下方法(未经测试,但可能对某些想法有用):


请告诉我destra是什么类型的变量,您在哪里设置它?
function shootBullo(e:TimerEvent):void
{
    var bullo:Bullo = new Bullo();
    bullo.x = Jumbo.x;
    bullo.y = Jumbo.y - 50; 

    if(destra) { bullo.dir = destra; }
    else { bullo.dir = sinistra; }

    bullo.addEventListener(Event.ENTER_FRAME, mainLoop);
}

function mainLoop (e:Event):void //the "e" of this function parameter is each unique "Bullo"
{
    //# currentTarget is whichever "bullo" is talking to this Event (via Listener).
    if (e.currentTarget.dir == destra) 
    { e.currentTarget.x += 10; }

    else { e.currentTarget.x -= 10; }

}