Wednesday, 16 November 2011

collision detection script

after creating two cubes and adding instance names cube1 and cube2 added this code



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

cube1.x+=3
cube2.x-=3
//
if (cube1.hitTestPoint(cube2.x,cube1.y,true)) {

cube2.alpha=.3;
}
}

also if you change cube2.alpha=.3; with cube2.play(); and after colision will play what ever is inside that movieclip (cube2) .

No comments:

Post a Comment