How do I make my hitTestObject() more precise?

随声附和 提交于 2019-12-23 05:22:26

问题


I'm doing some collision detection with a circle and a square and whenever the circle comes in contact with the square it bounces away changing its X coordinate by *-1. However, the Hit Area of the circle is a square, so even when it collides with the white area around the circle , the affect still occurs.

My question is, is there a way to modify the hit area to closer resemble my circle?

Thanks


回答1:


Bitmap hit testing is pixel based (instead of boundary-based, like Sprite-based hit testing), so it is inherently more precise.

Here are the Adobe docs on it.

Here is a nice tutorial on it.

And here is a nice code snippet on it:

if (firstObjectBitmapData.hitTest(new Point(firstObject.x, firstObject.y), 255, secondObjectBitmapData, new Point(secondObject.x, secondObject.y), 255))
{
    trace("hit!");
}


来源:https://stackoverflow.com/questions/11533626/how-do-i-make-my-hittestobject-more-precise

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