什么是java.awt.geom.Area的android等价物? [英] What is the android equivalent of java.awt.geom.Area?
问题描述
我想将复杂的形状构建为两个圆和一个矩形的交集。经过研究, java.awt.geom.Area 类对于此任务似乎很完美。
但是,当我发现 awt
包不包含android SDK 。有没有人知道任何替代品的android,允许我创建复杂的形状,通过定义简单形状的联合和交叉?
注意:使用图形裁剪绘制形状doesn因为我不只是想绘制形状,我还希望将这些形状存储在内存中以进行碰撞检测和其他交互。 解析方案 Android的java.awt.geom.Area替代方案
$ b 编辑:@numan在Android SDK中使用了一些类,在原始答案的时候我没有意识到:
https://developer.android.com/reference/android/graphics/Region.html
https://developer.android。 com / reference / android / graphics / Region.Op.html
Region 允许您定义几何区域,然后你可以用 Region.Op使用
Region
s op()
方法 enum
来计算交点和更复杂的形状。
其他一些选项
您可以使用 Canvas
绘制自定义形状,特别是使用剪辑*方法:
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#shape-drawable
http://developer.android.com/guide /topics/graphics/opengl.html
如果您的图形保持不变(或大致相同),则可以使用其他一些不错的选项:
http://developer.android.com/guide/topics/graphics/2d -graphics.html#drawables-from-xml
我发现一个很好的解决方案是使用9个补丁的drawables:
http:/ /developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
碰撞检测
这可能是为了你的目的而矫枉过正,但是有许多游戏物理库:
http://www.andengine.org http ://code.google.com/p/ande ngineexamples /
a>
http://www.dremsus.com/index.php/2012/01/box2d-game-demo-in-android/
或者您可以推出自己的解决方案:
http://cooers.blogspot.com/2012/08/simple-collision-detection-in-2d.html
http://content.gpwiki .org / index.php / Polygon_Collision
http://www.codeproject.com/Questions / 244344 / Android中的碰撞检测
这完全取决于目的;对于游戏,你可能最好只使用一个库;但如果碰撞检测是您需要的唯一功能,那么您最好自己动手节省资源。
额外奖励:Android库的一些索引
http:/ /www.appbrain.com/stats/libraries/dev
http://www.theultimateandroidlibrary.com/
http://www.openintents.org/zh/
I want to build complex shapes as the intersection of two circles and a rectangle. After researching a bit, java.awt.geom.Area class seems perfect for this task.
I was dismayed, however, when I discovered that the awt
package doesn't come with the android SDK. Does anyone know of any alternatives for android that allows me to create complex shapes by defining the union and intersection of simpler shapes?
Note: Using graphics clipping to draw the shape doesn't work because I don't just want to draw the shapes, I also want to store the shapes in memory to do collision detection and other interactions.
Android Alternatives to java.awt.geom.Area
EDIT: @numan pointed out an excellent option using some classes in the Android SDK that I was unaware of at the time of the original answer:
https://developer.android.com/reference/android/graphics/Region.html https://developer.android.com/reference/android/graphics/Region.Op.html
Region
allows you to define geometric areas, and then you can use Region
s op()
method with Region.Op
enum
to calculate intersections and more complex shapes.
Some other options
You can use a Canvas
to draw custom shapes, particularly using the clip* methods:
http://developer.android.com/reference/android/graphics/Canvas.html
Here are some pages about 2d graphics in Android:
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/opengl.html
Some other good options if your graphics remain the same (or roughly the same) are XML-based:
http://developer.android.com/guide/topics/graphics/2d-graphics.html#drawables-from-xml
And one solution I find quite neat, is using 9-patch drawables:
http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
Collision detection It might be overkill for your purposes, but there are a number of game physics libraries:
http://www.andengine.org http://code.google.com/p/andengineexamples/
http://www.dremsus.com/index.php/2012/01/box2d-game-demo-in-android/
Android, libgdx and box2d basics
Or you can roll your own solution:
http://cooers.blogspot.com/2012/08/simple-collision-detection-in-2d.html
http://content.gpwiki.org/index.php/Polygon_Collision
http://www.codeproject.com/Questions/244344/Collision-Detection-in-Android
Collision detection for rotated bitmaps on Android
It really depends on the purpose; for games, you'd probably be best to just use a library; but if collision detection is the only feature you need, you'd be better off doing it yourself to save resources.
Extra Credit: Some indexes of Android libraries
http://www.appbrain.com/stats/libraries/dev
http://www.theultimateandroidlibrary.com/
http://www.openintents.org/en/
这篇关于什么是java.awt.geom.Area的android等价物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!