如何让我的hitTestObject()更precise? [英] How do I make my hitTestObject() more precise?

查看:239
本文介绍了如何让我的hitTestObject()更precise?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一些碰撞检测与圆形和方形,每当圈进来的方形它反弹走改变由* -1的X坐标接触。但是,圆的点击区域是一个正方形,所以即使当它与周围一圈白色区域碰撞时,影响仍然存在。

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?

感谢

推荐答案

位图打测试是基于像素的(而不是边界为基础,似雪碧为基础的命中测试),所以它本质上更precise。

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

<一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#hitTest%28%29"相对=nofollow>此处是它的的Adobe文档。

Here are the Adobe docs on it.

这里是它一个很好的教程。

Here is a nice tutorial on it.

和这里是它一个很好的code片断:

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!");
}

这篇关于如何让我的hitTestObject()更precise?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆