3/22/2011

hitTest in as3

//設置mc_ball跟mc_ground的碰撞
//Because this is AS3 everything needs to be called through
  

//eventlisteners, so this first lin calls and listens for the ball  
ball.addEventListener(Event.ENTER_FRAME, enter_frame);  
//here is our function, it is called at the beginning of the movie  
function enter_frame(event:Event):void{  
    //An if statement, saying if the ball touches the ground,  
    //then just make a trace of text.  
    if (ball.hitTestObject(ground)) {  
        trace("碰撞了")  
    } else {  
        trace("還沒碰撞"
}  
}  
 
oringinal code from here

No comments:

Post a Comment