0

所以我得到了这个子弹容器类,它可以发射所有这些子弹,当我把这个类放在一个移动剪辑中添加到舞台上时,它工作得很好并且射击得很好。我不能在电影剪辑中使用它,因为当我调用 bulletClass 的函数时,它会向我发送一个错误,说它不存在。现在,我的问题是当我 addChild(bulletClass) 到舞台上时,除了运动/动画之外,它会完全按照它的编程方式工作。子弹移动得很好,除非我朝相反方向射击,而不只是朝相反方向射击旋转与我一起射击。所以它基本上就像我说的那样,它基本上是低音-akwards,而且只有当我 addChild() 带有一个类(扩展了 Movieclip)时。我不 不知道为什么我给你我的代码,因为它只会让你更加困惑,一切都检查出来了;我认为在某处进行了转换,例如扩展 Movieclip 的类的方向与 Library MovieClip 的方向不同?

此代码在 bulletAdder() 函数中,它是在 bulletContainer 中创建项目符号的唯一位置

var localPlayer = Object(root).localSurvivor;

//Select what movieclip should go into the bullet
var newBullet;
    newBullet = new bullet1;

//Create a local movieclip for this
var newBulletMC:MovieClip = new MovieClip;
    newBulletMC.addChild(newBullet);
    newBulletMC.x = setX;
    newBulletMC.y = setY;
    //trace(localPlayer.rotation);

//Create the newBullet class for movement
var localPlayerRotation = Object(root).localSurvivor.rotation;
trace(localPlayerRotation);
var newBulletClass:bulletClass = new bulletClass(localPlayerRotation, bulletLifetime);

//Add bulletMC to the bulletClass
    newBulletClass.addChild(newBulletMC);

//Add to array
    bulletArray.push(newBulletClass);

//Add to stage
    localStage.addChild(newBulletClass);

这是 bulletClass,在屏幕上移动的子弹

package  com{
        import flash.display.*
        import flash.utils.*

    public class bulletClass extends MovieClip{
            public var lifetime = 0;
            public var dir = 0;
                    var animationInt;
        public function bulletClass(playerRotation, bLifetime:Number = 1){
            dir = playerRotation
            //Start life
            animationInt = setInterval(animateBullet, 40);

        }

        private function animateBullet(){
            this.x += 10 * Math.sin(dir * (Math.PI / 180));
            this.y += 10 * Math.cos(dir * (Math.PI / 180));
        }

    }

}
4

1 回答 1

1

看来你已经整理好了?

我会建议一件事——当你做这样的事情时,使用显示列表并不总是有意义的。如果你在舞台上发生了很多事情,它会放慢速度,表演会很快变得粗略。

如果您正在构建游戏,我强烈建议您至少检查一两个大型 Flash 游戏框架。他们在幕后为你做了很多优化,甚至大部分游戏逻辑都为你抽象出来。例如,查看 Flixel - 超级容易快速启动和运行,并且有很多教程。

只是我的两分钱,希望它有帮助!

于 2011-03-13T01:50:44.677 回答