0 Replies - 1158 Views - Last Post: 04 April 2010 - 03:53 AM

#1 Ben91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 27-January 10

hitTestObject

Posted 04 April 2010 - 03:53 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.

var score:int;
var collisionOccurred:Boolean;
gameScore.text = "0";

score = 0;
collisionOccurred = false;

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;
			}
		}
	}
}

This post has been edited by Ben91: 04 April 2010 - 03:54 AM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1