womposan
August 13th, 2008, 07:53 PM
Hi,
Im creating a basic collision detection for my game. I have created two arrays: 1 for bullets and 1 for objects. For collision detection im using AS3.0's hitTestObject() function (it's enough for a space shooter :vader:). Upon collision (bullet vs. object) bullet is removed and object takes damage depending on players weapon. This is the collisionDetection function:
function collisionDetection(event:TimerEvent):void {
var i:int = myBulletArray.length;
var ii:int = myObjectArray.length;
while (ii--) {
while (i--) {
if (myBulletArray[i].hitTestObject(myObjectArray[ii])) {
removeChild(myBulletArray[i]);
myBulletArray[i] = null;
myBulletArray.splice(i,1);
myObjectArray[ii]._hp -= player.Damage(player._weapon);
}
}
}
}
CollisionDetection is run by a timed eventlistener (10 times per second):
var myTimer:Timer = new Timer(100);
myTimer.addEventListener(TimerEvent.TIMER, collisionDetection);
myTimer.start();
But when i run the game, following error occurs every timer tick:
TypeError: Error #1010: A term is undefined and has no properties.
at Game_fla::MainTimeline/collisionDetection()
at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
at flash.utils::Timer/flash.utils:Timer::tick()
I have read that a possible cause for this is that i'm refering to mcs that haven't been created yet... Knowing this, i still haven't figured this out. If someone knows how to deal with this, any help would be appreciated!!:crying:
Im creating a basic collision detection for my game. I have created two arrays: 1 for bullets and 1 for objects. For collision detection im using AS3.0's hitTestObject() function (it's enough for a space shooter :vader:). Upon collision (bullet vs. object) bullet is removed and object takes damage depending on players weapon. This is the collisionDetection function:
function collisionDetection(event:TimerEvent):void {
var i:int = myBulletArray.length;
var ii:int = myObjectArray.length;
while (ii--) {
while (i--) {
if (myBulletArray[i].hitTestObject(myObjectArray[ii])) {
removeChild(myBulletArray[i]);
myBulletArray[i] = null;
myBulletArray.splice(i,1);
myObjectArray[ii]._hp -= player.Damage(player._weapon);
}
}
}
}
CollisionDetection is run by a timed eventlistener (10 times per second):
var myTimer:Timer = new Timer(100);
myTimer.addEventListener(TimerEvent.TIMER, collisionDetection);
myTimer.start();
But when i run the game, following error occurs every timer tick:
TypeError: Error #1010: A term is undefined and has no properties.
at Game_fla::MainTimeline/collisionDetection()
at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
at flash.utils::Timer/flash.utils:Timer::tick()
I have read that a possible cause for this is that i'm refering to mcs that haven't been created yet... Knowing this, i still haven't figured this out. If someone knows how to deal with this, any help would be appreciated!!:crying: