将 libgdx 添​​加到 Android 原生应用程序 [英] Adding libgdx to an Android Native Application

查看:23
本文介绍了将 libgdx 添​​加到 Android 原生应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的儿童应用程序,可以教授颜色、数字等内容,我目前正在开发中.它使用我认为的标准 android java 编程(单 Xml/java 类)".我还有一个简单的恐龙游戏,它使用 libgdx 跳过字母.

I have a simple kids app which teaches things such as colors, numbers, etc... which I am currently developing. It uses what I would consider "standard android java programming (Single Xml/java class)." I also have a simple game with a Dinosaur that jumps over letters using libgdx.

我的问题是,我希望将游戏作为整体"应用的一部分.我想知道是否可以将 libgdx 游戏添加到 android 本机应用程序中.我尝试将适当的文件添加到我的应用程序中,但这会导致编译错误,有人可以指出我可以在此问题上找到帮助的地方,或者让我知道我想要做的事情是否可能?谢谢.

My question is, I would like to have the game as part of the "overall" app. I would like to know if it is even possible to add a libgdx game to an android native application. I tried adding the appropriate files to my app, but this caused a compile error, could someone point me to a place where I could find help on this issue, or perhaps let me know if what I am wanting to do is even possible? Thanks.

---澄清一下,我的主应用程序有一个菜单,可以带您进行活动.我希望 libgdx 游戏成为其中一项活动.

---To clairify, my main app has a menu which takes you to activities. I would like the libgdx game to be one of the activities.

---编辑响应---我使用 Gradle 进行编译并且出现的错误多得我数不清.我已经从应用程序中删除了 libgdx 游戏,所以我不确定具体的错误,但 iirc 有超过 100 个,其中许多是 R 问题,我本可以弄清楚,但我在任何一个上都找不到任何东西所以或者网络上说甚至可以将 libgdx 添​​加到非 libgdx 应用程序中.

---Edit to response---I compile using Gradle and have more errors than I can count. I've since removed the libgdx game from the app so I am not sure of specific errors, but iirc there were over 100, many of which were R issues, which I could have figured out, but I couldn't find anything on either S.O. or the web saying it was even possible to add libgdx to a non-libgdx app.

推荐答案

您可以将您的应用程序与您的 libgdx 游戏集成.
AndroidLauncher.java 是您的 libgdx Activity,您可以使用 Intent 从一个 Activity 移动到另一个.

You can integrate your App with your libgdx game.
AndroidLauncher.java is your libgdx Activity and you can move from one activity to another using Intent.

intent = new Intent(this, AndroidLauncher.class);
startActivity(intent);

并从 libgdx AndroidLauncher.java 移动,您需要从核心项目类中调用它.您需要使用接口.

and movement from libgdx AndroidLauncher.java, you need to call it from inside the core project classes. You need to use an interface.

https://github.com/libgdx/libgdx/wiki/Interfacing-with-platform-specific-code

如果您的游戏是您的应用程序的子视图.
AndroidApplication 类(它扩展了活动)有一个名为 initializeForView(ApplicationListener, AndroidApplicationConfiguration) 的方法,该方法将返回一个您可以添加到的视图你的布局.

If your game is sub view of your App.
The AndroidApplication class (which extends activity) has a method named initializeForView(ApplicationListener, AndroidApplicationConfiguration) that will return a View you can add to your layout.

优点-您已经拥有代码,只需要集成即可.
缺点-您需要维护 OpenGL Context Loss.Libgdx 为你做的.

Pros.-Code is already you have,only you need to integrate.
Cons.-you need to maintain OpenGL Context Loss. Libgdx do for you.

这篇关于将 libgdx 添​​加到 Android 原生应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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