Thursday, 13 October 2011

Collision detection demo

stage.addEventListener(Event.ENTER_FRAME, checkhit);
//Listen to the stage on every frame

function checkhit(myevent:Event):void {

cube1.x+=3
cube2.x-=3

if (cube1.hitTestPoint(cube2.x,cube2.y,true)){
//If any of the cubes get hit by the mouse in it's x or y direction, true means the i from blockarray is following the cubes, so the cube that is hit by the mouse will cause the transparency(alpha) down.
cube2.alpha=.3;

}


}

No comments:

Post a Comment