2D Framework updates (GameTimer & Auto-Repeat - Example Vid from Android Game)

These are actually pretty nice (and very useful) updates.

  1. AnimLayer now has a pause & resume method, allowing you to only pause sections of your game associated with the AnimLayer’s update loop.

  2. AnimManager can now manage GameTimer(s) for you.

  3. GameTimer is now abstract and calls onComplete(float time); when the timer finishes.

  4. GameTimers can now be set to auto-repeat.

Example usage:
GameTimer attack = new GameTimer(interval) {
public void onComplete(float time) {
// Executed each time the timer completes
if (dirIndex == 9) dir = false;
else if (dirIndex == 0) dir = true;
if (dir) dirIndex++;
else dirIndex–;

// Somewhere in you code… add the timer

// Somewhere else in your code… remove the cycling timer

EDIT: Also note that a timer that is not set to auto-repeat will be executed once and then removed/unflagged as managed.

EDIT 2: I guess it is also worth mentioning that GameTimer can be used for anything… they don’t have to be associated with the library components. They are a great way of keeping your update loop from looking like a CENSORING THE F BOMB… SORRY bowl of spaghetti.

That’s all for now.

1 Like

oops… ignore this :wink:

Another small update for GameTimer that allows you to set up a series of commands at different intervals with the use of setNextDuration calls from onComplete.

You have a series of commands/animations that you need to run at different intervals. For instance, you want a ship to release smaller attacker ships. The port needs to:

  1. Open (duration .5f)
  2. Release the series of attacker ships (duration 5f)
  3. Close (duration .5f)
  4. Reset for next use (turn off auto-repeat to flush the timer from the queue)

All this can be easily accomplished with a single timer now:

GameTimer releaseTimer;
float animDuration = .5f;
float openDuration = 5f;

// Methods to perform said actions
private void openPort(boolean open) {
// Open the port, run associated animations, etc
if (open) {
// open the port, etc
} else {
// close the port, etc

private void releaseAttackShips() {
// Release the ships, stay open and vulnerable for a period of time

// Defining the timer to execute the series of commands and then flush from the queue once complete
public void initTimer() {
releaseTimer = new GameTimer() {
public void onComplete(float time) {
if (getRunCount() == 1) {
} else if (getRunCount() == 2) {
} else if (getRunCount() == 3) {
} else if (getRunCount() == 4) {
// Disable auto-repeat to flush from the queue

// In your update loop
public void update(float tpf) {
if (!screen.getAnimManager().hasGameTimer(releaseTimer)) {
// Reset game timer start time to 0
// Re-enable auto-repeat
// Set the initial duration
// Reset the run count
// Add the timer

1 Like

Thought I’d add a vid from the current Android game I’m working on (a version of the Galaga type clone in Android friendly version):


This uses the above technique for handling all mothership scripts.

EDIT: Heh… the whole reason I posted this was to mention:

  1. I’ll be adding this to the Play Store soon
  2. I’ll be posting a link to the project so you can pick through it for ideas.

Hey that looks great i will buy the game for my android smartphone or so =). i will try to programm my 2d game too to show some stuff

1 Like
@Snowsun92 said: Hey that looks great i will buy the game for my android smartphone or so =). i will try to programm my 2d game too to show some stuff

I’m adding this as a free app. It’s my testbed for the 2D framework. Once it’s released, I’ll post the project here for others to go through.

1 Like