I'm working in a view based application and am trying to find some code that will let me grab some pixel colors from one of my images and use it for collision detection against one of my UIImageViews but haven't had any luck finding anything on this subject. So if my UIImageView for my player collides with the UIImageView of my map && collides with the color black in my image that's placed inside of my map view... then run collision code... or something along those lines.
我在一个基于视图的应用程序中工作,我正在尝试找到一些代码,这些代码可以让我从我的一个图像中获取一些像素颜色,并将其用于对我的一个UIImageViews进行碰撞检测但是没有任何运气这个主题。因此,如果我的播放器的UIImageView与我的地图的UIImageView发生碰撞,那么我的图像中的黑色会与我的地图视图中的颜色发生碰撞...然后运行碰撞代码......或者沿着那些线条运行。
1 个解决方案
#1
Is your question about getting the pixel color, or about doing collision detection?
您有关获取像素颜色或进行碰撞检测的问题吗?
If you want to get the pixel color, I'm not sure there's an easy way to do it - you may have to mess with your current graphics context to get it, and nothing is coming up in the docs.
如果你想获得像素颜色,我不确定是否有一种简单的方法 - 你可能不得不弄乱当前的图形上下文来获取它,并且文档中没有任何内容。
If it's just collision detection you want to do, take a look at UIView's convertPoint:toView:
and convertPoint:fromView:
methods. They let you take defined points within a given view and get their equivalents in other views. With some basic math on the resultant points, you could theoretically do some pretty good collision detection without having to worry about pixel colors.
如果它只是你想做的碰撞检测,请看看UIView的convertPoint:toView:和convertPoint:fromView:方法。它们允许您在给定视图中获取已定义的点,并在其他视图中获取它们的等价物。通过对结果点进行一些基本的数学运算,理论上可以做一些非常好的碰撞检测,而不必担心像素颜色。
#1
Is your question about getting the pixel color, or about doing collision detection?
您有关获取像素颜色或进行碰撞检测的问题吗?
If you want to get the pixel color, I'm not sure there's an easy way to do it - you may have to mess with your current graphics context to get it, and nothing is coming up in the docs.
如果你想获得像素颜色,我不确定是否有一种简单的方法 - 你可能不得不弄乱当前的图形上下文来获取它,并且文档中没有任何内容。
If it's just collision detection you want to do, take a look at UIView's convertPoint:toView:
and convertPoint:fromView:
methods. They let you take defined points within a given view and get their equivalents in other views. With some basic math on the resultant points, you could theoretically do some pretty good collision detection without having to worry about pixel colors.
如果它只是你想做的碰撞检测,请看看UIView的convertPoint:toView:和convertPoint:fromView:方法。它们允许您在给定视图中获取已定义的点,并在其他视图中获取它们的等价物。通过对结果点进行一些基本的数学运算,理论上可以做一些非常好的碰撞检测,而不必担心像素颜色。