PDA

View Full Version : Game: HIT TEST


nimrod_king
03-12-2008, 03:10 PM
Im making a game, you driving a car, if either of the 2 police cars hit you, you get busted.

----------------------
function onEnterFrame ():Void {
collide = _root.police1.hitTest(_root.car1)
collide = _root.police2.hitTest(_root.car1);
if (police1._x < 500)
if (police2._x < 500)
{

if (collide == true)

{
setProperty ( police1, _visible, true );
setProperty ( police2, _visible, true );
setProperty ( car1, _visible, false );

gotoAndPlay(5);
}
}
}

--------------------
only police1 works

anyone help?

fnx
03-12-2008, 04:27 PM
You're using the same boolean var collide for both cars, you should declare 2 variables, one for each police car you have, and then check if both are true

andrewProgrammer
03-31-2008, 08:33 PM
First off, the hitTest is NOT true or false. It does not have a value. what you need to do is say:

if(_root.police1.hitTest(_root.car1))
{
if((_root.police1._x < 500) and (_root.police2._x < 500))
{
_root.police1._visible = false
_root.police2._visible = false
_root.car1._visible = false
_root.gotoAndPlay(5)
}
}
else
{
if(_root.police2.hitTest(_root.car1))
{
if((_root.police1._x < 500) and (_root.police2._x < 500))
{
_root.police1._visible = false
_root.police2._visible = false
_root.car1._visible = false
_root.gotoAndPlay(5)
}
}
}