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 以360度的角度射出多发子弹?_Actionscript 3_Actionscript - Fatal编程技术网

Actionscript 3 以360度的角度射出多发子弹?

Actionscript 3 以360度的角度射出多发子弹?,actionscript-3,actionscript,Actionscript 3,Actionscript,我想要这种效果: 所以无论我点击哪里,它都会用子弹制造炸弹。 这是到目前为止我的代码。现在它只在鼠标方向上创建项目符号。 对不起,如果代码很乱 shotDex = new Timer(timerDelay2); shotDex.addEventListener(TimerEvent.TIMER, shot); stage.addEventListener(MouseEvent.MOUSE_DOWN, shootBullet); stage.addEventListener(MouseEven

我想要这种效果:

所以无论我点击哪里,它都会用子弹制造炸弹。 这是到目前为止我的代码。现在它只在鼠标方向上创建项目符号。 对不起,如果代码很乱

shotDex = new Timer(timerDelay2);
shotDex.addEventListener(TimerEvent.TIMER, shot);

stage.addEventListener(MouseEvent.MOUSE_DOWN, shootBullet);
stage.addEventListener(MouseEvent.MOUSE_UP, dontShoot);

    public var angleRadian = Math.atan2(mouseY + 42.75,mouseX + 331.7);
    public var angleDegree = angleRadian * 180 / Math.PI;
    public var speed1:int = 10;

    public var shotDex:Timer;
    public var timerDelay2:int = (250);
    public function shot(tEvt:TimerEvent)
    {
        var _bullet2:bullet2 = new bullet2;
        _bullet2.x = 300;
        _bullet2.y = 300;
        _bullet2.angleRadian = Math.atan2(mouseY + 42.75,mouseX + 331.7);
        _bullet2.addEventListener(Event.ENTER_FRAME, bulletEnterFrame);
        stage.addChild(_bullet2);
    }
    public function shootBullet(evt:MouseEvent)
    {
        var _bullet2:bullet2 = new bullet2;
        _bullet2.x = 300;
        _bullet2.y = 300;
        _bullet2.angleRadian = Math.atan2(mouseY + 42.75,mouseX + 331.7);
        stage.addChild(_bullet2);
        _bullet2.addEventListener(Event.ENTER_FRAME, bulletEnterFrame);
        shotDex.start();
    }
    public function bulletEnterFrame(evt:Event)
    {
        var _bullet2 = evt.currentTarget;
        _bullet2.x +=  Math.cos(_bullet2.angleRadian) * speed1;
        _bullet2.y +=  Math.sin(_bullet2.angleRadian) * speed1;
        _bullet2.rotation = _bullet2.angleRadian * 180 / Math.PI;
        if (_bullet2.x < 0 || _bullet2.x > 600 || _bullet2.y < 0 || _bullet2.y > 600)
        {
            stage.removeChild(_bullet2);
            _bullet2.removeEventListener(Event.ENTER_FRAME, bulletEnterFrame);
        }
    }
    public function dontShoot(evt:MouseEvent)
    {
        shotDex.stop();
    }
shotDex=新定时器(timerDelay2);
shotDex.addEventListener(TimerEvent.TIMER,shot);
stage.addEventListener(MouseEvent.MOUSE_DOWN,shootBullet);
stage.addEventListener(MouseEvent.MOUSE_UP,dontShoot);
公共变量angleRadian=Math.atan2(mouseY+42.75,mouseX+331.7);
公共var angleDegree=angleRadian*180/Math.PI;
公共变量1:int=10;
公共变量shotDex:计时器;
公共变量timerDelay2:int=(250);
公共功能快照(tEvt:TimerEvent)
{
var_bullet2:bullet2=新bullet2;
_bullet2.x=300;
_2.y=300;
_bullet2.angleRadian=Math.atan2(mouseY+42.75,mouseX+331.7);
_bullet2.addEventListener(Event.ENTER_FRAME,bulletEnterFrame);
阶段。添加孩子(_bullet2);
}
公共功能子弹(evt:MouseeEvent)
{
var_bullet2:bullet2=新bullet2;
_bullet2.x=300;
_2.y=300;
_bullet2.angleRadian=Math.atan2(mouseY+42.75,mouseX+331.7);
阶段。添加孩子(_bullet2);
_bullet2.addEventListener(Event.ENTER_FRAME,bulletEnterFrame);
shotDex.start();
}
公共功能公告框(evt:事件)
{
var_bullet2=evt.currentTarget;
_bullet2.x+=数学cos(_bullet2.angleRadian)*速度1;
_bullet2.y+=数学正弦(_bullet2.angleRadian)*速度1;
_bullet2.旋转=_bullet2.角度弧度*180/Math.PI;
如果(|bullet2.x<0 | | | | | bullet2.x>600 | | | bullet2.y<0 | | | bullet2.y>600)
{
第二阶段:移除儿童(2);
_bullet2.删除EventListener(Event.ENTER_FRAME,bulletEnterFrame);
}
}
公共函数dontShoot(evt:MouseEvent)
{
shotDex.stop();
}

您需要为每个项目符号提供不同的角度,其值均匀分布在0弧度和
2*Math.PI之间
弧度:

public function shootBulletCircle(evt:MouseEvent) {
    var shots:Number = 12; // Number of shots in the circle
    for (var i=0; i<shots; i++) {
        var _bullet2:bullet2 = new bullet2;
        _bullet2.x = 300;
        _bullet2.y = 300;
        _bullet2.angleRadian = (i/shots)*(2*Math.PI);
        stage.addChild(_bullet2);
        _bullet2.addEventListener(Event.ENTER_FRAME, bulletEnterFrame);
    }
}
公共函数(evt:MouseEvent){
var shots:Number=12;//圆圈中的快照数

对于(var i=0;iGlad to help,@Matt!如果您的问题已经解决,您应该接受答案。这可能也适用于您以前的一些问题。:)