Beginning Android Games

      Mario Zechner
Who am I?
Who am I?
Who am I?
Who am I?
Who am I?
Who am I?
Who am I?
Who am I?
Who am I?




   @badlogicgames
http://www.badlogicgames.com/
What I‘ll Talk About
•   Why Android?
•   What‘s in a game?
•   Android for game developers
•   Frameworks & engines
Why Android?
Why Android?
Why Android?
Why Android?




… or how to not make an infographic …
Why Android?




A Gaming Machine For Everyone!
What‘s in a Game?
What‘s in a Game?



  DESIGN
What‘s in a Game?
What‘s in a Game?
What‘s in a Game?
What‘s in a Game?
What‘s in a Game?
What‘s in a Game?
What‘s in a Game?



Technology
What‘s in a Game?
•   Window & Life-Cycle Management
•   File I/O
•   Input Devices
•   Audio
•   Graphics
•   Networking
•   Social Media Integration
•   Payment System
•   Tools
•   … you actually read all of this?
Android for Game Developers
Android for Game Developers




 + Tooling       + Performance
 + API Access    + Portability
 - Performance   - Tooling
 - Portability   - API Access
Android for Game Developers
Android for Game Developers
Android for Game Developers
• Store files in
   – APK (read-only)
   – Internal Storage (read/write, limited space)
   – External Storage (read/write)
• SharedPreferences for simple settings
• GOTCHAS
   – APK size limit (50mb)
   – Asset file compression bug until Android 2.3
   – No direct access via NDK in older Android versions
Android for Game Developers
• OnTouchListener and OnKeyListener on
  View
• SensorManager for
  compass, accelerometer, gyro, …
• USB/NFC since Android 3+
• GOTCHAS
  – Horrible Touch API
  – Multi-touch broken on many devices
Android for Game Developers
• SoundPool for sound effects
• MediaPlayer for streaming music
• OpenSL ES in C/C++
                                   setVolumeControlStream(AudioManager.STREAM_MUSIC);
                                   soundPool = new SoundPool(20, AudioManager.STREAM_MUSIC,
                                   0);

• GOTCHAS
                                   explosionId = soundPool.load(descriptor, 1);
                                   soundPool.play(explosionId, 1, 1, 0, 0, 1);


  – High latency (+100ms)
  – Broken drivers    mediaPlayer = new MediaPlayer()
                      mediaPlayer.setDataSource(descriptor.getFileDescriptor(),
                                       descriptor.getStartOffset(), descriptor.getLength());
                                   mediaPlayer.prepare();
                                   mediaPlayer.setLooping(true);
                                   mediaPlayer.start()
Android for Game Developers
                            Canvas                                         OpenGL ES
canvas.drawRGB(255, 255, 255);
paint.setColor(Color.RED);
canvas.drawLine(0, 0, canvas.getWidth()-1, canvas.getHeight()-1, paint);

paint.setStyle(Style.STROKE);
paint.setColor(0xff00ff00);
canvas.drawCircle(canvas.getWidth()/2, canvas.getHeight()/2, 40, paint);

paint.setStyle(Style.FILL);
paint.setColor(0x770000ff);
canvas.drawRect(100, 100, 200, 200, paint);




                + Ease-of-Use                                              + Performance
                - Performance                                              + 2D / 3D
                - 2D-only                                                  - Ease-of-Use
Android for Game Developers
                            Canvas                                         OpenGL ES
canvas.drawRGB(255, 255, 255);
paint.setColor(Color.RED);
canvas.drawLine(0, 0, canvas.getWidth()-1, canvas.getHeight()-1, paint);

paint.setStyle(Style.STROKE);
paint.setColor(0xff00ff00);
canvas.drawCircle(canvas.getWidth()/2, canvas.getHeight()/2, 40, paint);

paint.setStyle(Style.FILL);
paint.setColor(0x770000ff);
canvas.drawRect(100, 100, 200, 200, paint);




                + Ease-of-Use                                              + Performance
                - Performance                                              + 2D / 3D
                - 2D-only                                                  - Ease-of-Use

                     MY GOD, IT‘S FULL OF GOTCHAS
Android for Game Developers
                            Canvas                                         OpenGL ES
canvas.drawRGB(255, 255, 255);
paint.setColor(Color.RED);
canvas.drawLine(0, 0, canvas.getWidth()-1, canvas.getHeight()-1, paint);

paint.setStyle(Style.STROKE);
paint.setColor(0xff00ff00);
canvas.drawCircle(canvas.getWidth()/2, canvas.getHeight()/2, 40, paint);

paint.setStyle(Style.FILL);
paint.setColor(0x770000ff);
canvas.drawRect(100, 100, 200, 200, paint);




                + Ease-of-Use                                              + Performance
                - Performance                                              + 2D / 3D
                - 2D-only                                                  - Ease-of-Use

                     MY GOD, IT‘S FULL OF GOTCHAS
Android for Game Developers
•   Bugs in shader compilers
•   Deviations from OpenGL ES specification
•   Highly varying performance
•   GPU dependent optimizations
•   Texture compression formats
•   …
Android for Game Developers
• And if you use Java …
• Garbage Collector pauses (+200ms)
• Varying maximum heap memory
• Direct ByteBuffers and Bitmaps counted
  against Java heap
• Method call overhead
Android for Game Developers
•   A lot better since 2.2, great since 4.0
•   Concurrent GC
•   JIT
•   Tons of bug fixes
•   GOTCHA
Android for Game Developers
Android for Game Developers




       FRAGMENTATION
Android for Game Developers




Screen Sizes, Aspect Ratios, Resolutions
Android for Game Developers
•   Pick target resolution/aspect ratio
•   Stretch or Clip on other aspect ratios
•   Ship multiple asset sizes
•   We‘ve done this on the PC, we can do it on
    Android!
Android for Game Developers
Android for Game Developers
• Device-specific driver bugs (audio, OpenGL ES)
• Android version-specific bugs
• Multiple test devices (3-4)
  – PowerVR, Mali, Snapdragon, Tegra
  – Low-end to high-end phones
  – Tablet
• Or use a framework/engine!
Frameworks & Engines




       Not exhaustive, visit
http://mobilegameengines.com/
Frameworks & Engines
$$$
Free
$$$
Free
$$$
Free
Free
$$$
              Not exhaustive, visit
       http://mobilegameengines.com/
WIP
• Java (lots of C/C++ under the hood)
• Develop on the desktop 90% of the time (no
  slow deploys, no emulator madness)
• Abstraction layers
  – Low-level: OpenGL ES, file i/o, input, audio, ...
  – Mid-level: shaders, textures, linalg, …
  – High-level: fonts, sprites, scene graph, …
• Pick and choose, see feature list
http://libgdx.badlogicgames.com/features.html
Spine, 2D skeletal animation editor
https://plus.google.com/100248578810918104811
Source & Releases
http://libgdx.badlogicgames.com/download.html
Docs
http://libgdx.badlogicgames.com/documentation.html
Forum
http://badlogicgames.com/forum/
Blog
http://www.badlogicgames.com
IRC
irc.freenode.org, #libgdx
Questions?
   @badlogicgames
http://www.badlogicgames.com/

Beginning android games

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
    Who am I? @badlogicgames http://www.badlogicgames.com/
  • 11.
    What I‘ll TalkAbout • Why Android? • What‘s in a game? • Android for game developers • Frameworks & engines
  • 12.
  • 13.
  • 14.
  • 15.
    Why Android? … orhow to not make an infographic …
  • 16.
    Why Android? A GamingMachine For Everyone!
  • 17.
  • 18.
    What‘s in aGame? DESIGN
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
    What‘s in aGame? Technology
  • 26.
    What‘s in aGame? • Window & Life-Cycle Management • File I/O • Input Devices • Audio • Graphics • Networking • Social Media Integration • Payment System • Tools • … you actually read all of this?
  • 27.
    Android for GameDevelopers
  • 28.
    Android for GameDevelopers + Tooling + Performance + API Access + Portability - Performance - Tooling - Portability - API Access
  • 29.
    Android for GameDevelopers
  • 30.
    Android for GameDevelopers
  • 31.
    Android for GameDevelopers • Store files in – APK (read-only) – Internal Storage (read/write, limited space) – External Storage (read/write) • SharedPreferences for simple settings • GOTCHAS – APK size limit (50mb) – Asset file compression bug until Android 2.3 – No direct access via NDK in older Android versions
  • 32.
    Android for GameDevelopers • OnTouchListener and OnKeyListener on View • SensorManager for compass, accelerometer, gyro, … • USB/NFC since Android 3+ • GOTCHAS – Horrible Touch API – Multi-touch broken on many devices
  • 33.
    Android for GameDevelopers • SoundPool for sound effects • MediaPlayer for streaming music • OpenSL ES in C/C++ setVolumeControlStream(AudioManager.STREAM_MUSIC); soundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0); • GOTCHAS explosionId = soundPool.load(descriptor, 1); soundPool.play(explosionId, 1, 1, 0, 0, 1); – High latency (+100ms) – Broken drivers mediaPlayer = new MediaPlayer() mediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength()); mediaPlayer.prepare(); mediaPlayer.setLooping(true); mediaPlayer.start()
  • 34.
    Android for GameDevelopers Canvas OpenGL ES canvas.drawRGB(255, 255, 255); paint.setColor(Color.RED); canvas.drawLine(0, 0, canvas.getWidth()-1, canvas.getHeight()-1, paint); paint.setStyle(Style.STROKE); paint.setColor(0xff00ff00); canvas.drawCircle(canvas.getWidth()/2, canvas.getHeight()/2, 40, paint); paint.setStyle(Style.FILL); paint.setColor(0x770000ff); canvas.drawRect(100, 100, 200, 200, paint); + Ease-of-Use + Performance - Performance + 2D / 3D - 2D-only - Ease-of-Use
  • 35.
    Android for GameDevelopers Canvas OpenGL ES canvas.drawRGB(255, 255, 255); paint.setColor(Color.RED); canvas.drawLine(0, 0, canvas.getWidth()-1, canvas.getHeight()-1, paint); paint.setStyle(Style.STROKE); paint.setColor(0xff00ff00); canvas.drawCircle(canvas.getWidth()/2, canvas.getHeight()/2, 40, paint); paint.setStyle(Style.FILL); paint.setColor(0x770000ff); canvas.drawRect(100, 100, 200, 200, paint); + Ease-of-Use + Performance - Performance + 2D / 3D - 2D-only - Ease-of-Use MY GOD, IT‘S FULL OF GOTCHAS
  • 36.
    Android for GameDevelopers Canvas OpenGL ES canvas.drawRGB(255, 255, 255); paint.setColor(Color.RED); canvas.drawLine(0, 0, canvas.getWidth()-1, canvas.getHeight()-1, paint); paint.setStyle(Style.STROKE); paint.setColor(0xff00ff00); canvas.drawCircle(canvas.getWidth()/2, canvas.getHeight()/2, 40, paint); paint.setStyle(Style.FILL); paint.setColor(0x770000ff); canvas.drawRect(100, 100, 200, 200, paint); + Ease-of-Use + Performance - Performance + 2D / 3D - 2D-only - Ease-of-Use MY GOD, IT‘S FULL OF GOTCHAS
  • 37.
    Android for GameDevelopers • Bugs in shader compilers • Deviations from OpenGL ES specification • Highly varying performance • GPU dependent optimizations • Texture compression formats • …
  • 38.
    Android for GameDevelopers • And if you use Java … • Garbage Collector pauses (+200ms) • Varying maximum heap memory • Direct ByteBuffers and Bitmaps counted against Java heap • Method call overhead
  • 39.
    Android for GameDevelopers • A lot better since 2.2, great since 4.0 • Concurrent GC • JIT • Tons of bug fixes • GOTCHA
  • 40.
    Android for GameDevelopers
  • 41.
    Android for GameDevelopers FRAGMENTATION
  • 42.
    Android for GameDevelopers Screen Sizes, Aspect Ratios, Resolutions
  • 43.
    Android for GameDevelopers • Pick target resolution/aspect ratio • Stretch or Clip on other aspect ratios • Ship multiple asset sizes • We‘ve done this on the PC, we can do it on Android!
  • 44.
    Android for GameDevelopers
  • 45.
    Android for GameDevelopers • Device-specific driver bugs (audio, OpenGL ES) • Android version-specific bugs • Multiple test devices (3-4) – PowerVR, Mali, Snapdragon, Tegra – Low-end to high-end phones – Tablet • Or use a framework/engine!
  • 46.
    Frameworks & Engines Not exhaustive, visit http://mobilegameengines.com/
  • 47.
    Frameworks & Engines $$$ Free $$$ Free $$$ Free Free $$$ Not exhaustive, visit http://mobilegameengines.com/
  • 48.
  • 49.
    • Java (lotsof C/C++ under the hood) • Develop on the desktop 90% of the time (no slow deploys, no emulator madness) • Abstraction layers – Low-level: OpenGL ES, file i/o, input, audio, ... – Mid-level: shaders, textures, linalg, … – High-level: fonts, sprites, scene graph, … • Pick and choose, see feature list http://libgdx.badlogicgames.com/features.html
  • 51.
    Spine, 2D skeletalanimation editor https://plus.google.com/100248578810918104811
  • 52.
  • 53.
    Questions? @badlogicgames http://www.badlogicgames.com/