Game Development Reference
In-Depth Information
var outHeight:Number;
world.Step(1/30,10,10);
for (var i:int=0; i<3; i++) {
maxHeight=sphereVector[i].GetUserData();
currHeight=sphereVector[i].GetPosition().y*worldScale;
maxHeight=Math.min(maxHeight,currHeight);
sphereVector[i].SetUserData(maxHeight);
outHeight=sphereVector[i].GetUserData();
trace("Sphere "+i+":"+Math.round(outHeight));
}
trace("---------------");
world.ClearForces();
world.DrawDebugData();
}
We want to keep track of the maximum height reached by each sphere, so we are
looking for the minimum value of y position in pixels of each sphere.
The changes that we saw just update the userData property with the minimum
value between userData itself that represent the highest y position tracked so far
and the current y position, and then print the result on the output window.
Test the movie and you will see the rightmost sphere doing a high jump, while the
remaining spheres seem to remain on the ground:
 
Search WWH ::




Custom Search