kendyb
12-10-2008, 02:26 AM
I am using classes in my flash game. I try to use the hitTest function but it does not work for me. Can someone please help me. In the following code, I have an array in the class ship called enemies that and I need collision between the missiles and the enemies passed on to the array. Here is my missile class:
class missile extends MovieClip
{
//speed of missle
var msleSpeed;
//function to set missle speed
function onLoad()
{
msleSpeed = 25;
}
//function to have missile actions
function onEnterFrame()
{
//speed missile moves at
_x += msleSpeed;
//if missile movieClip greater than 600 pixels, remove missile movieClip from stage
if(_x > 1000)
{
//to remove missile movieClip
this.removeMovieClip();
}
//check the enemies array in the ship class, if this hits enemy1, enemy1 explode
for(var i in _root.ship.enemies)
{
if(this.hitTest(_root.ship.enemies[i]))
{
//remove the shot
this.removeMovieClip();
//find the enemy ship in the array declared in the ship class and call the explode function
_root.ship.enemies[i].explode();
_root.ship.updateScore(50);
}
}
}
}
class missile extends MovieClip
{
//speed of missle
var msleSpeed;
//function to set missle speed
function onLoad()
{
msleSpeed = 25;
}
//function to have missile actions
function onEnterFrame()
{
//speed missile moves at
_x += msleSpeed;
//if missile movieClip greater than 600 pixels, remove missile movieClip from stage
if(_x > 1000)
{
//to remove missile movieClip
this.removeMovieClip();
}
//check the enemies array in the ship class, if this hits enemy1, enemy1 explode
for(var i in _root.ship.enemies)
{
if(this.hitTest(_root.ship.enemies[i]))
{
//remove the shot
this.removeMovieClip();
//find the enemy ship in the array declared in the ship class and call the explode function
_root.ship.enemies[i].explode();
_root.ship.updateScore(50);
}
}
}
}