I've made a loop which will create a random number of asteroids, and a function which will create a lazer when space bar is pressed, the lazer is then added to a container.
Im attempting to get collision detection working between the two but cant get it to work. I know hit test object isnt the best way to do it, but should the code below work ?
ActionScript Code:
public function mainGame(evt:Event):void {
// collision *************************
//for every child in the LAZER container
for (var a:Number=0; a < this.shotContainer.numChildren; a++) {
//make variable for current lazer
b = this.shotContainer.getChildAt(a) as J_lazer;
//for every child in the ASTEROID container
for (var c:Number=0; a<this.container.numChildren; a++) {
//make variable for current asteroid
d = this.container.getChildAt(c) as J_asteroid;
if (this.d.hitTestObject(this.b)) {
trace('hit');
} else {
trace('nope')
}
}
}
}