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

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

问题描述

我用贝塞尔曲线在我的libgdx项目。我用测试桌面版的java.awt.geom 的GeneralPath 但是当我去测试在Android上,它提出了一个错误,说我不能导入 java.awt中的。机器人都有相应的类的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.)

从技术上讲,你可以把code,它依赖于AWT在桌面Libgdx后端,并把code,它依赖于Android的的GeneralPath在你的Andr​​oid Libgdx后端,然后创建可以访问到正确的接口实现从普通code。请参见 https://github.com/libgdx/libgdx /维基/接口与 - 平台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 equvialents仿制点和路径。我觉得多边形 Vector2 中的 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或安卓类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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