Android Activity 中的 LibGDX

LibGDX inside Android Activity(Android Activity 中的 LibGDX)

本文介绍了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

基础教程推荐