One of the highest priority design goals of MHF3 is cross-platform portability between Android and PC-based platforms. With this in mind to help guide my design decisions, the initial setup for both platforms follows a simple, three-step process, with only a slight modification to the Android version:
- Create at least one screen. This is done by inheriting from the engine's MHScreen class. (More on this in a future post.)
- Define your display settings by initializing an MHVideoSettings object.
- Pass those things into the engine along with the window in which your game app will run. This is accomplished with a call to MHFramework.run().
Here's a PC-compatible example of a main class that accomplishes these things.
import javax.swing.JFrame;
import com.mhframework.MHFramework;
import com.mhframework.MHScreen;
import com.mhframework.MHVideoSettings;
public class PlatformTestPCWindow
{
public static void main(String[] args)
{
// Step 1: The screen.
MHScreen startingScreen = new TestScreen();
// Step 2: The video settings.
MHVideoSettings displaySettings = new MHVideoSettings();
displaySettings.displayWidth = 800;
displaySettings.displayHeight = 480;
// Step 3: Run it!
MHFramework.run(new JFrame(), startingScreen, displaySettings);
}
}
The Android version takes a very similar approach, but with a few additional rules:
- The main class must inherit from the engine's MHAndroidActivity class, which is a specialization of Android's basic Activity class that adds additional support for MHF3's multithreading requirements.
- Rather than perform those steps in main, your program must override the Activity.onCreate() method.
- Since Android's orientation can be specified as portrait or landscape, this must be specified here as well.
- Future versions may simply add the orientation constant as a field in MHVideoSettings and default it to landscape. This way, the Android version will use the exact same three steps with no additional requirements.
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import com.mhframework.MHFramework;
import com.mhframework.MHScreen;
import com.mhframework.MHVideoSettings;
import com.mhframework.platform.android.MHAndroidActivity;
public class PlatformTestAndroid extends MHAndroidActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
// Initialize Android-specific properties.
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
// Step 1: The screen.
MHScreen startingScreen = new TestScreen();
// Step 2: The video settings.
MHVideoSettings displaySettings = new MHVideoSettings();
displaySettings.displayWidth = 800;
displaySettings.displayHeight = 480;
// Step 3: Run it!
MHFramework.run(this, startingScreen, displaySettings);
}
}
No comments:
Post a Comment