Rev 219 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 210 | chris | 1 | package com.gebauz.Bauzoid.app; |
| 2 | |||
| 3 | import com.badlogic.gdx.ApplicationListener; |
||
| 4 | |||
| 5 | /** Base class for applications using Bauzoid engine. */ |
||
| 211 | chris | 6 | public abstract class BauzoidApp implements ApplicationListener |
| 210 | chris | 7 | { |
| 214 | chris | 8 | protected Game mGame = null; |
| 217 | chris | 9 | private long mSystemTimeMs = System.currentTimeMillis(); |
| 210 | chris | 10 | |
| 11 | public BauzoidApp() |
||
| 12 | { |
||
| 13 | } |
||
| 14 | |||
| 15 | @Override |
||
| 16 | public void create() |
||
| 17 | { |
||
| 18 | mGame = new Game(); |
||
| 19 | mGame.init(); |
||
| 211 | chris | 20 | |
| 21 | initGame(); |
||
| 217 | chris | 22 | |
| 23 | mSystemTimeMs = System.currentTimeMillis(); |
||
| 210 | chris | 24 | } |
| 25 | |||
| 26 | @Override |
||
| 27 | public void dispose() |
||
| 28 | { |
||
| 211 | chris | 29 | exitGame(); |
| 30 | |||
| 210 | chris | 31 | mGame.exit(); |
| 32 | mGame = null; |
||
| 33 | } |
||
| 34 | |||
| 35 | @Override |
||
| 36 | public void pause() |
||
| 37 | { |
||
| 213 | chris | 38 | mGame.pause(); |
| 210 | chris | 39 | } |
| 40 | |||
| 41 | @Override |
||
| 42 | public void resume() |
||
| 43 | { |
||
| 219 | chris | 44 | mGame.resume(); |
| 210 | chris | 45 | } |
| 46 | |||
| 47 | @Override |
||
| 48 | public void resize(int w, int h) |
||
| 49 | { |
||
| 213 | chris | 50 | mGame.resize(w, h); |
| 210 | chris | 51 | } |
| 52 | |||
| 53 | @Override |
||
| 54 | public void render() |
||
| 55 | { |
||
| 217 | chris | 56 | long currentTimeMs = System.currentTimeMillis(); |
| 57 | long deltaTimeMs = currentTimeMs - mSystemTimeMs; |
||
| 58 | mSystemTimeMs = currentTimeMs; |
||
| 212 | chris | 59 | |
| 217 | chris | 60 | mGame.update((float)deltaTimeMs / 1000.0f); |
| 212 | chris | 61 | |
| 62 | mGame.render(); |
||
| 210 | chris | 63 | } |
| 64 | |||
| 211 | chris | 65 | /** Called after the engine internals have been initialized - this is the point to kick off the initial game state. */ |
| 66 | public abstract void initGame(); |
||
| 67 | |||
| 68 | /** Called before the engine internals are cleaned up. */ |
||
| 69 | public abstract void exitGame(); |
||
| 214 | chris | 70 | |
| 71 | /** Get the instance of the game. */ |
||
| 72 | public Game getGame() |
||
| 73 | { |
||
| 74 | return mGame; |
||
| 75 | } |
||
| 210 | chris | 76 | |
| 77 | } |