LibGDX inside Android Activity(Android Activity 中的 LibGDX)
问题描述
我正在为 Android 开发一个小型应用程序,使用 Android UI 和活动进行大部分交互,但是一个关键方面需要使用 LibGDX(使用 3D 模型和物理).我希望能够在我的应用程序(我的激活"类)中单击一个按钮,该按钮将打开初始化并运行所有 LibGDX 代码的AndroidApplication"类(我的Bobble"类).
I'm in the middle of developing a small app for Android using the Android UI and activities for the most part of the interaction, however one key aspect requires the use of LibGDX (using 3D models and physics). I want to be able to click a button in my app (my "Activate" class) which will open the "AndroidApplication" class (my "Bobble" class) that initializes and runs all the LibGDX code.
我的问题是我不能使用Intent"来启动 AndroidApplication 类(据我所知只有一个 Activity).我敢肯定,过去人们不得不解决这个问题,所以任何帮助都会很棒.
My problem is that I can't use an "Intent" to start an AndroidApplication class (only an Activity as far as I can tell). I'm sure that people have had to work around this issue in the past so any help would be fantastic.
到目前为止,这是我的代码:
Here's my code so far:
public class Activate extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try
{
setContentView(R.layout.activate_screen);
Button b_Run = (Button) findViewById(id.bActiveRun);
b_Run.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent to_Bobble = new Intent(v.getContext(), Bobble.class);
startActivity(to_Bobble);
}
});
}
catch (Exception e)
{
Log.e("Activate", "Error in activity", e);
Toast.makeText(getApplicationContext(),
e.getClass().getName() + " " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
}
}
public class Bobble extends AndroidApplication {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LifeCycle loop = new LifeCycle();
loop.ddgSettings = new ddgSystemSettings(this);
initialize(loop, false);
}
}
推荐答案
好的,我现在可以确认上面的代码完全没有问题.问题是我没有在 AndroidManifest 文件中声明我的Bobble"类/文件,这导致了运行时错误.
Ok I can now confirm that there is no issue at all with the above code. The issue was that I hadn't declared my "Bobble" class/file in the AndroidManifest file, and that was causing the runtime error.
这篇关于Android Activity 中的 LibGDX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android Activity 中的 LibGDX
基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01