LibGDX - 有条件地使用 java 或 android 类

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

问题描述

我在我的 libgdx 项目中使用贝塞尔曲线.我正在使用 java.awt.geom 和 GeneralPath 测试桌面版本,但是当我在 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 等效项用于通用点和路径.我认为 PolygonVector2package-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 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)