How do I detect collision detection in flash AS3?

淺唱寂寞╮ 提交于 2019-12-06 03:49:52

You can use the Collision Detection Kit : https://code.google.com/p/collisiondetectionkit/

prototypical

One way you could do this, is to use hitTestPoint() method to test if any of the corners have hit your wall.

hitTestPoint() tests only a single location to see if that point collides with an object. This is how you could test the top left corner of your monkey to see if it's touching the wall :

// I am assuming that x,y is the top left corner of your monkey

if (wall.hitTestPoint(monkey.x, monkey.y, true))
{
   // top left collided with wall
{

So you could do the same for all corners, or if you want, you can determine any collision points you want to check for the monkey.

Depending on your level of precision, this method might work just fine for your needs. But if you want pixel perfect collision, you can check out this link :

http://www.freeactionscript.com/2011/08/as3-pixel-perfect-collision-detection/

VC.One

Why would it mean individual walls?? Have you tried drawing your maze shape/walls and selecting them all at once, right-click to convert selection to a movieclip giving preferred name. Then also give it instance name "wall". Now try to run it and your handleCollision function should work.

Or try changing from hitTestObject to hitTestPoint in your collision check...

function handleCollision(e:Event):void
{ 
 if (wall.hitTestPoint (monkey.x, monkey.y, false)) 
    { trace("HIT"); } 
else 
    { trace("MISS"); } 
}

Also check this article for more clarification..
http://www.actionscriptmoron.com/AS3Tutorials/hittest-hittestpoint/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!