Actionscript [Collision of 2 Movie Clips]

Go down

Actionscript [Collision of 2 Movie Clips]

Post by Wingedge on Tue Oct 14, 2008 3:11 am

There are 2 instances called MC_Target && MC, we will determine if the two movie clips collided
and display trace message "hit" when it does we will be using HitTest function.

Movieclip.HitTest(Targetx,Targety,true) returns true if Movieclip's x & y is the same as the targets x and y.

[frame]
Code:

// let MC follow wherever the mouse moves
MC.onMouseMove = function(){
  MC._x = _root._xmouse;
  MC._y = _root._ymouse;
}

Mouse.hide(); // hide mouse;

// mouse is clicked
MC.onMouseDown= function(){
  //check collision
  if(MC_Target.hitTest(MC)){
    trace("hit");//displays this when MC hits MC_Target and button is clicked
  }
}

avatar
Wingedge
Admin
Admin

Male
Number of posts : 77
Age : 34
Name : Sir Francis
Year Level : Instructor
Location : UC
Registration date : 2008-06-10

Credits
GP: 9999

View user profile

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum