Once at school, we continued to animate a car moving around the screen. What I accomplished last week was keeping the car on the stage by cutting the speed to 0 when it hit the ed of the stage. Now we are adding obstacles, which adds a new level of fun, both programming wise, and playwise.
It's pretty easy to moniter a hit between 2 objects, but each object is surronded by a an invisible box. When Flash records a hit, it is when the two boxes overlap, but the eye, the objects are afair distance apart:
There is a trick out there to watch different coloured pixels overlap, that will take some research.
Another issue some people were having was removing a child from the stage. We created the obstacle in an array of obstacles, but removing individual elements are turning oout to be a bit of a complicated pain. Some more reasearch is required.
UPDATE: Getting this error when I try to remove a child
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at DocClass/HitObject()
Here is what my code looks like:
for ( var count:int = 0; count < NUM_OBS; count++ ) {
if ( car_mc.hitTestObject( obsArray[count] ) )
{
trace("HIT!! KABOOM!!" );
obsArray[count].scaleX /= 2;
obsArray[count].scaleY /= 2;
//obsArray[count].play();
car_mc.speed = 0;
trace(obsArray[count].scaleX + " " + obsArray[count].scaleY);
if ( obsArray[count].scaleX < 0.125 )
removeChild( obsArray[count] );
}
}
Keeping in mind I am trying to manage an array of obstacles for a simple car game.
Powered by ScribeFire.

No comments:
Post a Comment