Introduction to libGDX

download Introduction to libGDX

If you can't read please download the document

  • date post

    22-Apr-2015
  • Category

    Technology

  • view

    203
  • download

    3

Embed Size (px)

description

Introduction to libGDX

Transcript of Introduction to libGDX

  • 1. Intro to libGDX Jussi Pohjolainen Tampere University of Applied Sciences
  • 2. libGDX and Android Streaming music, sound effects Wav, mp3, ogg Audio Recording support Accelerometer, Compass, Gestures (taps, pinch zooming) High-level 2D APIs Sprites, Textures, Fonts, Tiles, UI - library High-level 3D APIs UOliOes: JSON, XML, File I/O (preferences), Math..
  • 3. Community & Support Forum http://badlogicgames.com/forum/ IRC irc.freenode.net, #libgdx Blog http://www.badlogicgames.com/ wordpress/ Twi0er https://twitter.com/badlogicgames
  • 4. App Framework: Applica'on Applica'on main entry point for your app hZp://libgdx.badlogicgames.com/nightlies/docs/api/com/ badlogic/gdx/ApplicaOon.html Equivalent to JFrame (Swing) or Activity (Android) Informs your game about events such as window resizing Developer creates a class that implements ApplicationListener, methods are called by Application ApplicaOon can be GwtApplication, IOSApplication
  • 5. public class MyGame extends ApplicationAdapter { SpriteBatch batch; Texture img; @Override public void create () { Debug.print("MyGdxGame", "create()", 1); batch = new SpriteBatch(); img = new Texture("badlogic.jpg"); } @Override public void render () { Debug.print("MyGdxGame", "render()", 2); Gdx.gl.glClearColor(1, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); batch.draw(img, 0, 0); batch.end(); } @Override public void resize(int w, int h) { Debug.print("MyGdxGame", "resize(), w = " + w + "h = " + h, 1); } }
  • 6. STARTER CLASSES
  • 7. About Starter Classes For each pla^orm (iOS, Android, Desktop ..) a starter class must be wriZen Starter classes are pla^orm dependent We will focus on Desktop (LWJGL) Android
  • 8. LWJGL? Lightweight Java Game Library (LWJGL) framework for creaOng games with Java libGDX is built on top of LWJGL See more: hZp://www.lwjgl.org/
  • 9. Starter Classes: Desktop // This is platform specific: Java SE public class DesktopStarter { public static void main(String[] argv) { LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); config.title = ; config.width = 480; config.heigth = 320; new LwjglApplication(new MyGame(), config); } }
  • 10. Starter Classes: Desktop public class DesktopLauncher { public static void main (String[] arg) { LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); MyGame game = new MyGame(); LwjglApplication app = new LwjglApplication(game, config); if(app.getApplicationListener() == game) { app.log("test", "success!"); } } }
  • 11. Starter Classes: Android import android.os.Bundle; import com.badlogic.gdx.backends.android.AndroidApplication; import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration; // This is platform specific: Android // No main public class AndroidLauncher extends AndroidApplication { @Override protected void onCreate (Bundle savedInstanceState) { super.onCreate(savedInstanceState); AndroidApplicationConfiguration config = new AndroidApplicationConfiguration(); MyGame game = new MyGame(); initialize(game, config); if(this.getApplicationListener() == game) { this.log("test", "success"); } } }
  • 12. Android Manifest
  • 13. Android Permissions Add permissions if your android app requires certain funcOonality Add these to manifest file See hZp://developer.android.com/guide/topics/ manifest/manifest-intro.html#perms
  • 14. Other important Modules (Interfaces) ApplicaOon Informs your game about events Files Exposes the underlying file system Input Mouse, keyboard, touch, accelerometer Net* Access HTTP(S) Audio Enables sound Graphics Exposes OpenGL ES 2.0 where available
  • 15. Accessing Modules All modules (previous slide) can be accessed via staOc fields of Gdx class Global public variables for easy access Example AudioDevice audioDevice = Gdx.audio.newAudioDevice(44100, false);
  • 16. Javadoc: Gdx Gdx.audio (Interface) is a reference to the backend implementaOon that has been instanOated on applicaOon startup by the ApplicaOon instance.
  • 17. Javadoc: Audio
  • 18. Querying ApplicaOon (Gdx.app) interface provides various methods to query properOes If(Gdx.app.getType() == Android) { }