LibGDX - Conditionally use java or android classes(LibGDX - 有条件地使用 java 或 android 类)
问题描述
我在我的 libgdx 项目中使用贝塞尔曲线.我正在使用 java.awt.geom 和
GeneralPath
测试桌面版本,但是当我在 android 上进行测试时,它引发了一个错误,说我无法导入 java.awt
.Android 有 GeneralPath
、Point2D
等对应的类,所以我的问题是如何在它们各自的环境中使用这些类?
I'm using bezier curves in my libgdx project. I was testing the desktop version using java.awt.geom
with GeneralPath
but when I went to test on android, it raised an error saying that I can't import java.awt
. Android have corresponding classes for GeneralPath
, Point2D
etc so my question is how can I use those classes in their respective environments?
推荐答案
Android 没有 AWT 实现,因此对这些类的引用在 Android 上不起作用.(在桌面上,您从 JDK 获取这些类.)
Android does not have an AWT implementation, so references to those classes won't work on Android. (On the desktop you're getting those classes from the JDK.)
从技术上讲,您可以将依赖于 AWT 的代码放入桌面 Libgdx 后端,并将依赖于 Android 的 GeneralPath 的代码放入您的 Android Libgdx 后端,然后创建一个接口,以便从您的通用代码中访问正确的实现.请参阅 https://github.com/libgdx/libgdx/wiki/Interface-with-platform-specific-code 了解一些细节.这似乎需要做很多工作,但它可能对您的设置有意义.
Technically, you can put code that depends on AWT in your desktop Libgdx backend, and put code that depends on Android's GeneralPath in your Android Libgdx backend, and then create an interface that provide access to the right implementation from your common code. See https://github.com/libgdx/libgdx/wiki/Interfacing-with-platform-specific-code for some details. That seems like a lot of work, but it may make sense for your setup.
或者,您可以将 Libgdx 等效项用于通用点和路径.我认为 Polygon 和 Vector2
package-summary.html" rel="nofollow">Libgdx 数学包 可能是你想要的.
Alternatively, you could use the Libgdx equvialents for generic points and paths. I think Polygon
and Vector2
in the Libgdx Math Package may be what you want.
这篇关于LibGDX - 有条件地使用 java 或 android 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:LibGDX - 有条件地使用 java 或 android 类


- android 4中的android RadioButton问题 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01