JME in Fragment?

Can I run JME in a Fragment? I only saw fullscreen examples.
If yes, how?

Sorry for asking such a dumb question but searching only gives me lots of “fragment shader” stuff.

Well it’s been pushed to master 1 or 2 weeks ago. It’s still experimental and you have to use master.
In 3.0 you can’t.
Maybe @iwgeric can tell you more about it.

1 Like

As @nehon says, jME 3.1 has been switched to use Android Fragment as default. Here is the link to what the file is on 3.1. jME Android Fragment. In addition to using Fragments, the Android layout XML file is now used to size the fragment within the Activity.

Once we go to Alpha (or Beta or whatever it ends up being), you will be able to create a new project in the SDK that is organized this way.

3 Likes

I just found out about this today and will try to get my cardboard stuff working with the fragment instead. Much smoother than the current CardboardHarness :smile:
Is the app entirely contained within the fragment?

Yes, the entire app is continental in the fragment.

contained? bad mobile phone completion?

Ha! Yes.

Awesome! Got it working.
I didn’t see anywhere it was actually used, nor a description, so here’s how I did it (using 3.1 trunk):

  1. The Android MainActivity should now extend Activity instead of AndroidHarness.

  2. It seems the preferred way of using AndroidHarnessFragment is by extending it. This way, you can set the protected fields (most importantly, appClass) from the constructor.

  3. Create a layout file (here called main.xml):

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <fragment android:name="com.mycompany.mygame.MyAndroidHarnessFragment"
              android:id="@+id/game_fragment"
              android:layout_width="match_parent"
              android:layout_height="match_parent" />
    

This has our fragment that extends AndroidHarnessFragment

  1. MainActivity should have the following method:
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    }

That’s it.

Edit: Published a slightly wordier (and better formatted) version here: http://www.softwarepioneering.com/2015/07/running-jmonkeyengine-3-on-android.html

1 Like

Are all fragments done Declaratively or Programmatically?

Help me on initializing JMEFragment programmatically in a android Activity and inflating to the defined container.