Hittesting工作正常但是将值设置为同一个对象会导致错误?

时间:2011-03-09 02:02:11

标签: arrays flash-cs5 flash-cs4 hittest projectile

我正在努力射击一些子弹,碰撞测试工作得非常好,甚至伤害了僵尸。除了一个问题,我希望子弹在击中僵尸时消失这听起来很容易感觉我已经在“bulletContainer”类中进行了测试,长话短说我称之为bulletContain [a] .killBullet();和输出dialouge说它不是一个函数(我知道它是一个函数和它自己正在加载的“bulletClass”类)。似乎有一次我创造子弹射击它有自己的头脑并且不听任何变量我在里面改变它告诉它需要消失/ killBullet()

如果您觉得自己需要更多(尽管没有太多),我的代码中的Heres Snippets会发表评论

BulletContainer Class(Showing Just testCollosion Function):

    //Collision Tester/////////////////////////////////////////////
        private function testCollision(){
            //Get number of bullets on screen
            var numBullets = bulletContain.length;

            //Define a local variable for ease of reference
            var localZombieContain = Object(root).zombieContain.zombieContain
            var numZombies:Number   = localZombieContain.length;

            //Loop through every bullet for collision test
            for(var a:Number = 0; a < numBullets; a++){
                //Loop through every zombie & hit test to see if bullet is hitting
                for(var b:Number = 0; b < numZombies; b++){
                    var killBullet:Boolean = false;
                    if(localZombieContain[b].hitTestObject(bulletContain[a])){
                        //Tell zombie it has been hit
                        localZombieContain[b].hurtZombie();

                        //Tell Bullet its dead for garbage
                        killBullet = true;
                     }

                     if(killBullet){

                         bulletContain[a].killBullet();
                         trace("BULLET DIED");
                     }
                }

            }

BulletClass(显示来自bulletClass的所有内容): (IGNORE REDENDENT SWITCH()编码,以供日后开发使用)

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

    public class bulletClass extends MovieClip{
             public var dead = 0;

                    var moveBulletInt;
        public function bulletClass(type:Number) {
            //Declare bullet types from library
            var tmpBullet1 = new bullet1;

            switch(type){
                case 1:
                    addChild(tmpBullet1);
                break;
            }

            //Move this bullet
            moveBulletInt = setInterval(moveBullet, 10);
        }

        public function killBullet(){
            clearInterval(moveBulletInt);
            trace("BULLET DIED");
        }

        private function moveBullet(){
            if(dead == 0){
                this.x += 15 * Math.sin((this.rotation - 90) * (Math.PI / 180));
                this.y += 15 * Math.cos((this.rotation - 90) * (Math.PI / 180));
            }
            if(dead == 1){
                //clearInterval(moveBulletInt);
                this.x = -100
                this.y = -100
            }

        }


    }

}

1 个答案:

答案 0 :(得分:0)

当我之前在我的代码中添加了项目符号时,我正在调用影片剪辑而不是调用该类。所以我最后只是做了new newObject = newBullet;而不是泡沫newObject.addChild(newBullet);