java.awt.geom.Area 在 Android 中的等价物是什么?

2024-01-10

我想构建复杂的形状作为两个圆形和一个矩形的交集。经过一番研究后,java.awt.geom.Area http://docs.oracle.com/javase/tutorial/2d/advanced/complexshapes.html类似乎非常适合这项任务。

然而,当我发现,awtandroid SDK 中不包含该软件包。有谁知道 Android 的任何替代方案可以让我通过定义更简单形状的并集和交集来创建复杂的形状?

注意:使用图形裁剪来绘制形状不起作用,因为我不仅仅是想绘制形状,我还想将形状存储在内存中以进行碰撞检测和其他交互。


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允许您定义几何区域,然后您可以使用Regions 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/

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

java.awt.geom.Area 在 Android 中的等价物是什么? 的相关文章

随机推荐