Would you like to react to this message? Create an account in a few clicks or log in to continue.

Actionscript [Collision of 2 Movie Clips]

Go down

Actionscript [Collision of 2 Movie Clips] Empty Actionscript [Collision of 2 Movie Clips]

Post by Wingedge 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
  }
}

Wingedge
Wingedge
Admin
Admin

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

Credits
GP: 9999

Back to top Go down

Back to top

- Similar topics

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