February 2010
M T W T F S S
« Jan   Mar »
1234567
891011121314
15161718192021
22232425262728

Detecting collisions of 2 movie clips

Problem
Need detect collision.

Solution
Using hitTestObject.

Detailed explanation
Please create 2 movie clips on your stage.

When one movie clip connect to other you must see ‘boom’ on the output window.


stage.addEventListener(KeyboardEvent.KEY_DOWN, starMoving);

function starMoving(event:KeyboardEvent):void

{

switch (event.keyCode)

{

case Keyboard.UP : star_mc.y-=10;

break;

case Keyboard.DOWN : star_mc.y+=10;

break;

case Keyboard.LEFT : star_mc.x=star_mc.x-10;

break;

case Keyboard.RIGHT : star_mc.x+=10;

break;

default:

break;

}

if(star_mc.hitTestObject(house_mc))

{

trace("boom");

}

}

index7

Source
detecting_collisions

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>