java.awt.geom.Area 的 Android 替代品
EDIT:@numan 指出了一个出色的使用 Android SDK 中的一些类的选项,我在原始答案时不知道这些类:
https://developer.android.com/reference/android/graphics/Region.html https://developer.android.com/reference/android/graphics/Region.html
https://developer.android.com/reference/android/graphics/Region.Op.html https://developer.android.com/reference/android/graphics/Region.Op.html
Region
允许您定义几何区域,然后您可以使用Region
s op()
方法与Region.Op
enum
计算交叉点和更复杂的形状。
其他一些选项
您可以使用Canvas
绘制自定义形状,特别是使用 Clip* 方法:
http://developer.android.com/reference/android/graphics/Canvas.html http://developer.android.com/reference/android/graphics/Canvas.html
以下是有关 Android 中 2d 图形的一些页面:
http://developer.android.com/guide/topics/graphics/2d-graphics.html http://developer.android.com/guide/topics/graphics/2d-graphics.html
http://developer.android.com/guide/topics/graphics/2d-graphics.html#shape-drawable http://developer.android.com/guide/topics/graphics/2d-graphics.html#shape-drawable
http://developer.android.com/guide/topics/graphics/opengl.html http://developer.android.com/guide/topics/graphics/opengl.html
如果您的图形保持相同(或大致相同),其他一些不错的选择是基于 XML 的:
http://developer.android.com/guide/topics/graphics/2d-graphics.html#drawables-from-xml http://developer.android.com/guide/topics/graphics/2d-graphics.html#drawables-from-xml
我发现一个非常巧妙的解决方案是使用 9-patch 可绘制对象:
http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
碰撞检测对于您的目的来说,这可能有点过分了,但是有许多游戏物理库:
http://www.andengine.org http://www.andengine.org http://code.google.com/p/andengineexamples/ http://code.google.com/p/andengineexamples/
http://bulletphysicals.org http://bulletphysics.org
http://www.emini.at/ http://www.emini.at/
http://www.dremsus.com/index.php/2012/01/box2d-game-demo-in-android/ http://www.dremsus.com/index.php/2012/01/box2d-game-demo-in-android/
Android、libgdx 和 box2d 基础知识 https://stackoverflow.com/questions/10420088/android-libgdx-and-box2d-basics
或者您可以推出自己的解决方案:
http://cooers.blogspot.com/2012/08/simple-collision-detection-in-2d.html http://cooers.blogspot.com/2012/08/simple-collision-detection-in-2d.html
http://content.gpwiki.org/index.php/Polygon_Collision http://content.gpwiki.org/index.php/Polygon_Collision
http://www.codeproject.com/Questions/244344/Collision-Detection-in-Android http://www.codeproject.com/Questions/244344/Collision-Detection-in-Android
Android 上旋转位图的碰撞检测 https://stackoverflow.com/questions/11475719/collision-detection-for-rotated-bitmaps-on-android
这实际上取决于目的;对于游戏,您可能最好只使用库;但如果碰撞检测是您唯一需要的功能,那么您最好自己动手以节省资源。
额外加分:Android 库的一些索引
http://www.appbrain.com/stats/libraries/dev http://www.appbrain.com/stats/libraries/dev
http://www.theultimateandroidlibrary.com/ http://www.theultimateandroidlibrary.com/
http://www.openintents.org/en/ http://www.openintents.org/en/