LibGDX - 有条件地使用 java 或 android 类 [英] LibGDX - Conditionally use java or android classes

查看:15
本文介绍了LibGDX - 有条件地使用 java 或 android 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 libgdx 项目中使用贝塞尔曲线.我正在使用 java.awt.geomGeneralPath 测试桌面版本,但是当我在 android 上进行测试时,它引发了一个错误,说我无法导入 java.awt.Android 有 GeneralPathPoint2D 等对应的类,所以我的问题是如何在它们各自的环境中使用这些类?

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 等效项用于通用点和路径.我认为 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 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆