Home  >  Article  >  Java  >  Actionscript3 implementation code for detecting collision of two movie clip components

Actionscript3 implementation code for detecting collision of two movie clip components

PHP中文网
PHP中文网Original
2017-08-19 13:46:142091browse

This article introduces how as3 detects the collision of two components.

The following code has been tested by me and is available.

First put two movie clips mc1 and mc2 in the scene

Put the following code in the as panel:

mc1.addEventListener(Event.ENTER_FRAME,MCMoveEvent);
mc2.gotoAndStop(1);
var bmd1 = new BitmapData(mc1.width, mc1.height, true, 0);
bmd1.draw(mc1);
var bmd2 = new BitmapData(mc2.width, mc2.height, true, 0);
bmd2.draw(mc2);
function MCMoveEvent(e:Event):void{ 
mc1.x-=0.5; 
if(bmd1.hitTest(new Point(mc1.x-1, mc1.y), 0x55, bmd2, new Point(mc2.x, mc2.y))){ 
 mc2.gotoAndStop(2); 
 mc1.removeEventListener(Event.ENTER_FRAME,MCMoveEvent); 
}else{ 
 mc2.gotoAndStop(1); 
}
}

Through the above code, you can see that actionscript collision is mainly implemented by the hitTest function. You can write collision in the if condition Business logic operation after success.

This article is provided by PHP Chinese website,

Article address: http://www.php.cn/java-article-377122.html

Come to PHP to learn programming Chinese website www.php.cn

The above is the detailed content of Actionscript3 implementation code for detecting collision of two movie clip components. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn