获取同一父项下两个子项的 hitTestPoint
我有一个父容器:背景,其中有任意数量的鱼和鱼食物对象作为子对象添加,并且它们有一个碰撞框,当鱼和食物碰撞时,如何获得它们碰撞的坐标?因为我想用坐标来做效果。那就是画一个波纹。有没有一种方法可以获取我的食物和鱼符号中的两个碰撞框碰撞时的坐标。
public function moveToFood():void
{
x -= (x - foodTarget.x) / 40;
y -= (y - foodTarget.y) / 40;
if (hit.hitTestObject(foodTarget.hit))
{
foodRipple.drawRipple(bg,bg.y, 10, 1);
foodTarget.removeSelf();
}
}
i have a parent container:Background, in it there is arbitrary amount of fishes and fish foods object added as childs, and they have a hit box, how can i get the coordinate of thier collision when the fish and food collide? because i want to use the coordinate to do a effect. that is to draw a ripple.Is there a method to get the coordinate of when the two hitboxes in my Food and Fish symbol when they collide.
public function moveToFood():void
{
x -= (x - foodTarget.x) / 40;
y -= (y - foodTarget.y) / 40;
if (hit.hitTestObject(foodTarget.hit))
{
foodRipple.drawRipple(bg,bg.y, 10, 1);
foodTarget.removeSelf();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议看一下“碰撞检测套件”
它可能会为您提供您正在寻找的像素完美的碰撞点。
http://code.google.com/p/collisiondetectionkit/
I would recommend taking a look at "Collision Detection Kit"
It may give you the pixel perfect collision point you are looking for.
http://code.google.com/p/collisiondetectionkit/
像您所描述的那样获得精确的碰撞检测需要一个库,因为 Flash 没有内置的库。实现这一目标的一种方法是使用 Box2D。
Getting exact collision detection like you describe requires a library because Flash doesn't have that built-in. One way to get there is to use Box2D.