像素碰撞检测?
在我的应用程序中,我有一堆 CCSprites,我希望有一个碰撞检测功能,该功能仅在 CCSprites 中的非透明像素发生碰撞时才起作用。我不想局限于碰撞精灵之间的颜色。我认为这就是 Cocos2D 论坛中“像素完美碰撞检测”线程所做的,但我想使用任何颜色来实现真正的碰撞。这种碰撞检测将在我的游戏循环中,因此它不会太昂贵。无论如何,有人对我如何做到这一点有任何想法吗? 如果可以的话,我愿意使用 Cocos2D、Box2D 或 Chipmunk 甚至 UIKit。
谢谢!
In my app, I have a bunch of CCSprites and I want to have a collision detection feature that will work only when the non-transparent pixels in the CCSprites collide. I don't want to be restricted to color between the colliding sprites. I think thats what the 'Pixel Perfect Collision Detection' thread does in the Cocos2D forum, but I want to use any color for the real collision. This collision detection would be in my game loop so it can't be too expensive. Anyway, does anyone have any ideas on how I can do this?
I am willing to use Cocos2D, Box2D or Chipmunk or even UIKit if it can do it.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当谈论硬件渲染图形时,“我想要像素完美的碰撞”和“我不希望它们太昂贵”是相当相互排斥的。
要么编写一个更简单的渲染器,不允许如此复杂的转换、抗锯齿或子像素放置,要么使用实际的 GPU 渲染某种碰撞遮罩。在 GPU 上执行此操作的问题在于,将数据发送到 GPU 的速度很快,而返回数据的成本却很高。这种技术非常不常见是有原因的。
Chipmunk Pro 的自动几何功能支持将各种类型的图像转换为碰撞形状,但尚未完成。
When talking about hardware rendered graphics, "I want pixel perfect collisions" and "I don't want them to be too expensive" are pretty mutually exclusive.
Either write a simpler renderer that doesn't allows such complex transformations, anti-aliasing or sub-pixel placement or use the actual GPU to render some sort of collision mask. The problem with doing that on the GPU is that it's fast to send stuff to the GPU and expensive to get it back. There's a reason why this technique is quite uncommon.
Chipmunk Pro's auto-geometry stuff supports turning images of various varieties into collision shapes, but isn't complete yet.
如果你不想损失性能,这是不可能的。尝试进行基于圆圈的系统碰撞,这是进行碰撞的最佳方式
It`s imposible to do if you dont want lose performance. Try to do a system colission based in circles, this in best way to do a collision