Steps to include the LionEngine in your project:
- lionengine-core (minimum requirement)
- lionengine-core-awt (required if you use AWT as graphic renderer, target for computer)
- lionengine-core-swt (required if you use SWT as graphic renderer, target for computer)
- lionengine-core-android (required if you use Android 1.5, target for phones)
- lionengine-game (base for game development)
- lionengine-network (support for network)
- lionengine-audio-wav (support for Wav sound)
- lionengine-audio-midi (support for Midi musics)
- lionengine-audio-sc68 (support for Sc68 Atari musics)
Once you installed the LionEngine in your project, you may would like to know how to prepare a quick sample as a first try.
gs.lionengine.example.core.minimal; import com.b3dgs.lionengine.Config; import com.b3dgs.lionengine.Resolution; import com.b3dgs.lionengine.Version; import com.b3dgs.lionengine.core.Loader; import com.b3dgs.lionengine.core.awt.Engine; /** * Program starts here. When you start the jvm, ensure that this main function is called. * * @author Pierre-Alexandre (contact@b3dgs.com) */ public class AppJava { /** * Main function called by the jvm. * * @param args The arguments. */ public static void main(String[] args) { // Start engine (name = "First Code", version = "1.0.0", resources directory = "resources") // The engine is initialized with our parameters: // - The name of our program: "First Code" // - The program version: "1.0.0" // - The main resources directory, relative to the execution directory: ./resources/ // This mean that any resources loaded with Media.get(...) will have this directory as prefix. // To load resources from JAR, this alternative is preferred if external folder is not possible: // Engine.start("AppJava", Version.create(1, 0, 0), AppJava.class); Engine.start("AppJava", Version.create(1, 0, 0), "resources"); // Resolution configuration (output = 640*480 at 60Hz). This is the output configuration. // As our native is in 320*240 (described in the Scene), the output will be scaled by 2. // If the current frame rate is lower than the required in the native, // the extrapolation value will allow to compensate any data calculation. final Resolution output = new Resolution(640, 480, 60); // Final configuration (rendering will be scaled by 2 considering source and output resolution). // This is the final configuration container, including color depth and window mode. final Config config = new Config(output, 16, true); // Program starter, setup with our configuration. It just needs one sequence reference to start. final Loader loader = new Loader(config); loader.start(Scene.class); } }
import com.example.test.Menu; public final class AppAndroid extends Activity { @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); Engine.start("AppAndroid", Version.create(1, 0, 0), this); final Resolution output = new Resolution(800, 480, 60); final Config config = new Config(output, 32, false); final Loader loader = new Loader(config); loader.start(Menu.class); } @Override public void finish() { super.finish(); Engine.terminate(); } }
gs.lionengine.example.core.minimal; import com.b3dgs.lionengine.Resolution; import com.b3dgs.lionengine.core.Graphic; import com.b3dgs.lionengine.core.Loader; import com.b3dgs.lionengine.core.Sequence; import com.b3dgs.lionengine.core.awt.Engine; import com.b3dgs.lionengine.core.awt.Keyboard; /** * This is where the game loop is running. A sequence represents a thread handled by the Loader. To link a sequence with * another one, a simple call to {@link Sequence#end(Class, Object...)} is necessary. This will terminate the current * sequence, and start the linked one. * * @author Pierre-Alexandre (contact@b3dgs.com) */ class Scene extends Sequence { /** Native resolution. */ private static final Resolution NATIVE = new Resolution(320, 240, 60); /** Keyboard reference. */ private final Keyboard keyboard = getInputDevice(Keyboard.class); /** * Constructor. * * @param loader The loader reference. */ public Scene(Loader loader) { super(loader, Scene.NATIVE); keyboard.addActionPressed(Keyboard.ESCAPE, new KeyboardAction() { @Override public void action() { end(); } }); } @Override protected void load() { // Load } @Override public void update(double extrp) { // Update } @Override public void render(Graphic g) { // Render } @Override protected void onTerminate(boolean hasNextSequence) { if (!hasNextSequence) { Engine.terminate(); } } }
Read next page: General architecture