Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.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
Class 如何更改另一个类的值?_Class_Actionscript 3_Variables_Angle_Projectile - Fatal编程技术网

Class 如何更改另一个类的值?

Class 如何更改另一个类的值?,class,actionscript-3,variables,angle,projectile,Class,Actionscript 3,Variables,Angle,Projectile,我有敌人级和子弹级 敌人是通过编程方式添加的,他们在自己的类文件中处理自己的移动 我该如何让他们开枪 在bullet类中,有一些变量 速度 角 等 但是我怎样才能得到正确的角度呢?我需要的角度是基于特定敌人射击子弹的旋转 所以我需要在bullet类文件中添加如下内容: “如果敌人向布拉巴开枪 addChild(本) 角度=(((基于敌人的旋转?))() 我怎么做?我不知道如何引用其他类中的变量 我知道_root.,但现在这无关紧要。在这种情况下,您的播放器可能有一个fire()函数来处理此问题

我有敌人级和子弹级

敌人是通过编程方式添加的,他们在自己的类文件中处理自己的移动

我该如何让他们开枪

在bullet类中,有一些变量

速度 角 等

但是我怎样才能得到正确的角度呢?我需要的角度是基于特定敌人射击子弹的旋转

所以我需要在bullet类文件中添加如下内容:

“如果敌人向布拉巴开枪 addChild(本) 角度=(((基于敌人的旋转?))()

我怎么做?我不知道如何引用其他类中的变量


我知道_root.,但现在这无关紧要。

在这种情况下,您的
播放器可能有一个
fire()
函数来处理此问题

作为一个非常简单的例子,您可能有:

public function fire():void
{
    var bullet:Bullet = new Bullet(x, y, rotation);
    stage.addChild(bullet);
}
您的
项目符号将接受起始位置和旋转:

class Bullet extends Sprite
{
    public function Bullet(x:int, y:int, rotation:Number)
    {
        this.x = x;
        this.y = y;
        this.rotation = rotation;
    }
}
这使得推进
fire()
函数以处理诸如玩家拥有不同武器、没有弹药等问题变得很容易:

public function fire():void
{
    if(currentWeapon.ammunition === 0) return;

    if(currentWeapon is Handgun)
    {
        // Make a HandgunBullet.
    }

    if(currentWeapon is Shotgun)
    {
        // Make a ShotgunBullet.
    }
}

谢谢!!但是,我得到了一个小错误。子弹发射得很好,但是如果我尝试检查碰撞,如果(this.hitTestObject(_root.刺客.hitbox)){u root.hitPoints-=30;this.parent.removeChild(this);removeEventListener(Event.ENTER_FRAME,loop);}然后我得到一个1009错误。同时,我在主类中得到一个奇怪的1063错误。@user3123633提供的代码只是粗略地告诉您一个想法。另外,我认为AS3中不存在
\u root
。if(this.x<0 | | this.x>\u root.stageWidth | this.y>\u root.stageWidth | | this.y<0){removeChild(this)也会发生同样的情况;removeEventListener(Event.ENTER_FRAME,loop);}:(我像这样使用私有变量_root:MovieClip;然后在构造函数中_root=MovieClip(root);