PDA

View Full Version : [AS3] collision - movie clip


krulos
04-15-2009, 02:57 PM
Hello everyone I have a small problem.. not sure how to fix it.

I have a game where there is pieces defined within an array. When they hit the bottom of the stage they stop. What im trying to do is when the pieces hit the ground theynow become part of the bottomwall

if (pieces[i].hitTestObject(bottomwall_mc)) {
pieces[i].y --;
}

Is there a way to define the piece when it hits the ground.. like when it hits the ground.. it now becomes bottomwall_mc as well - so other pieces can stack on top of them now.


thanks :)

apiccion
04-16-2009, 01:18 AM
hitTestObject only tests if the bounding boxes of two objects are overlapping. This is important to remember, because if you are coliding anything but a square, you will get false positives.

One solution could be to make an array of DisplayObjects which compose the bottom wall. For example, var bottomWallList:Array.

Then when an object hits bottomWall you append it to the array.

Your hit test code would look like
for each i in bottomWallList
i.hitTestObject(myObject);