Thursday, 13 October 2011

Collision

After that we have done some collision work, this is the coding we have done.


stage.addEventListener(Event.ENTER_FRAME, checkhit);
function checkhit(myevent:Event) :void {

cube1.x+=3       //cube1 goes at the speed of three to the right
cube2.x-=3        //cube2 goes at the speed of three to the right

if (cube1.hitTestPoint(cube2.x,cube2.y,true)) {       //if cube1 and cube2 collide, cube1 fades
cube2.alpha=.3;
}
}

No comments:

Post a Comment