Ben91
04-04-2010, 10:49 AM
Hi i've been making skeetshoot game as part of an assignment.
However the hitTestObject part is not working exactly how i want it.
When a bullet hits a gameskeet or gameskeet2 i want the score to increase by 10 and it to be displayed in the dynamic text. It does this but then goes back to 0.
I'm not sure if it's because i've put some if statements in to get past the problem with some objects being null as at times they aren't on the stage.
I'd really appreciate some help with this as i'm stuck at what to do.
I've put the section of code below. I apologise if it isn't concise- I'm a flash noob xD.
Thanks, Ben.
function updateGameScore():void {
score+=10;
gameScore.text = String(score);
}
stage.addEventListener(Event.ENTER_FRAME, collisionDetector);
function collisionDetector (event:Event):void {
if (bullet != null)
{
if (gameskeet != null)
{
if (gameskeet.hitTestObject(bullet))
{
if (!collisionOccurred)
{
updateGameScore();
collisionOccurred = true;
removeChild(gameskeet);
}
}
else
{
collisionOccurred = false;
}
}
else if (gameskeet2 != null)
{
if (gameskeet2.hitTestObject(bullet))
{
if (!collisionOccurred)
{
updateGameScore();
collisionOccurred = true;
removeChild(gameskeet2);
}
}
else
{
collisionOccurred = false;
}
}
}
}
However the hitTestObject part is not working exactly how i want it.
When a bullet hits a gameskeet or gameskeet2 i want the score to increase by 10 and it to be displayed in the dynamic text. It does this but then goes back to 0.
I'm not sure if it's because i've put some if statements in to get past the problem with some objects being null as at times they aren't on the stage.
I'd really appreciate some help with this as i'm stuck at what to do.
I've put the section of code below. I apologise if it isn't concise- I'm a flash noob xD.
Thanks, Ben.
function updateGameScore():void {
score+=10;
gameScore.text = String(score);
}
stage.addEventListener(Event.ENTER_FRAME, collisionDetector);
function collisionDetector (event:Event):void {
if (bullet != null)
{
if (gameskeet != null)
{
if (gameskeet.hitTestObject(bullet))
{
if (!collisionOccurred)
{
updateGameScore();
collisionOccurred = true;
removeChild(gameskeet);
}
}
else
{
collisionOccurred = false;
}
}
else if (gameskeet2 != null)
{
if (gameskeet2.hitTestObject(bullet))
{
if (!collisionOccurred)
{
updateGameScore();
collisionOccurred = true;
removeChild(gameskeet2);
}
}
else
{
collisionOccurred = false;
}
}
}
}