我有一个在 Inkscape 中编辑的 PNG 图像。它是一个不规则的锯齿状形状,但我需要用它进行碰撞检测。它太大了,无法在它周围制作粗略的矩形(它占用的不仅仅是标准手机屏幕)。所以我一直在 INkscape 中围绕它绘制矩形并记下这些矩形的像素尺寸。
我的意图是使用这些“虚构”矩形的联合进行碰撞检测。然而,我的努力遇到了障碍。手机上图片的默认大小似乎与 Inkscape 中的不同。
我想知道对大型不规则物体进行碰撞检测的最佳方法,和/或如何使画布位图测量值与其像素(或毫米)测量值相同。
我有一个在 Inkscape 中编辑的 PNG 图像。它是一个不规则的锯齿状形状,但我需要用它进行碰撞检测。它太大了,无法在它周围制作粗略的矩形(它占用的不仅仅是标准手机屏幕)。所以我一直在 INkscape 中围绕它绘制矩形并记下这些矩形的像素尺寸。
我的意图是使用这些“虚构”矩形的联合进行碰撞检测。然而,我的努力遇到了障碍。手机上图片的默认大小似乎与 Inkscape 中的不同。
我想知道对大型不规则物体进行碰撞检测的最佳方法,和/或如何使画布位图测量值与其像素(或毫米)测量值相同。
What I suggest to do is to create an equivalent image where you have defined your collision area with a value of 1, and the non collision area with a value of 0 (or 0 and 255).
So, you will have two images, the colourful one which you will display, and the collision image where you will load.
Then, you can detect if you are inside a collision area with:
Bitmap collision;
collision = BitmapFactory.decodeStream(...yourImage...);
collision.getPixel(x,y)
Another solution is to create two arrays post processing the collision image, you could do that creating a Java application that process your original image and creates a text file with two lines, first line is the x coordinate and the second line is the pair y coordinate.
Then, read this file in your Android application and if your x and y exist in this array, is a collision point.