我正在射击一些子弹,碰撞测试工作得非常好,甚至伤害了僵尸。除了一个问题,我希望子弹在击中僵尸时消失,这听起来很容易我已经在“bulletContainer”类中进行了测试,长话短说我称之为bulletContain[a].killBullet(); 并且输出对话框说它不是一个函数(我知道事实上它是一个函数并且它自己正在正确加载的“bulletClass”类)。似乎一旦我创建子弹射击它就有自己的想法并且不听我在里面改变的任何变量让我告诉它需要消失/killBullet()
Heres我的代码片段,如果你觉得你需要更多请评论(虽然没有太多)
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 的所有内容):(忽略 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
}
}
}
}