<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2897325714589840286</id><updated>2024-09-10T08:59:18.373-07:00</updated><category term="development"/><category term="gwt"/><category term="game"/><category term="java"/><category term="BREW"/><category term="MIDP"/><category term="aglie"/><category term="design"/><category term="ide"/><category term="planning"/><title type='text'>Java Game Development</title><subtitle type='html'>Late Night Java Programming</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://javagamedevel.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2897325714589840286/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://javagamedevel.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Andrew</name><uri>http://www.blogger.com/profile/09635073990556546451</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2897325714589840286.post-7409129364415580255</id><published>2015-04-27T04:58:00.000-07:00</published><updated>2015-04-27T05:12:04.201-07:00</updated><title type='text'>LIBGDX dependency injection with Dagger</title><content type='html'>So I&#39;ve given up on &lt;a href=&quot;http://www.frontierquestgame.com/&quot;&gt;writing games with JavaScript&lt;/a&gt; and decided to go back to good old Java. I love Java, and now with &lt;a href=&quot;http://libgdx.badlogicgames.com/&quot;&gt;LIBGDX &lt;/a&gt;creating cross platform games has never been easier (and fun!).&lt;br /&gt;
&lt;br /&gt;
In this article, I&#39;m going to focus on enhancing the LIBGDX library to accommodate dependency injection with the lightweight IoC &lt;a href=&quot;http://square.github.io/dagger/&quot;&gt;Dagger&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
Note - this method has only been tested on the Desktop and Android LIBDGX deployments, however, as Dagger pre-complies dependencies it *should* work on other platforms, but alas I haven&#39;t got around to testing the HTML or IOS deployments yet .&lt;br /&gt;
&lt;br /&gt;
The basic design I&#39;m going to follow is to provide an adapter class to handle the construction of the Dagger object graph and delegate calls to the game&#39;s ApplicationListener. We need to make sure we follow the LIBGDX ApplicationListener&#39;s interface, otherwise the object graph will be created before the LIBGDX game engine has had a chance to initialise itself.&lt;br /&gt;
&lt;br /&gt;
So here we go.&lt;br /&gt;
&lt;br /&gt;
First up we will make sure we have the correct dependencies in our Gradle build file. I don&#39;t pretend to be a Gradle guru, but this seems to be working fine for me:&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;
build.gradle
&lt;/span&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;buildscript {
    repositories {
        mavenCentral()
        maven { url &quot;https://oss.sonatype.org/content/repositories/snapshots/&quot; }
    }
    dependencies {
        classpath &quot;com.android.tools.build:gradle:1.0.0&quot;
        classpath &quot;com.neenbedankt.gradle.plugins:android-apt:1.4+&quot;
    }
}

allprojects {
    apply plugin: &quot;eclipse&quot;
    apply plugin: &quot;idea&quot;
    version = &#39;1.0&#39;
    ext {
        appName = &#39;example-game&#39;
        gdxVersion = &#39;1.5.6&#39;
        roboVMVersion = &#39;1.0.0&#39;
        box2DLightsVersion = &#39;1.3&#39;
        ashleyVersion = &#39;1.3.1&#39;
        aiVersion = &#39;1.5.0&#39;
    }

    repositories {
        mavenCentral()
        maven { url &quot;https://oss.sonatype.org/content/repositories/snapshots/&quot; }
        maven { url &quot;https://oss.sonatype.org/content/repositories/releases/&quot; }
    }
}

project(&quot;:desktop&quot;) {
    apply plugin: &quot;java&quot;
    dependencies {
        compile project(&quot;:core&quot;)
        compile &quot;com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion&quot;
        compile &quot;com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop&quot;
        compile &quot;com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop&quot;
    }
}

project(&quot;:android&quot;) {
    apply plugin: &quot;android&quot;
    apply plugin: &quot;com.android.application&quot;
    apply plugin: &quot;com.neenbedankt.android-apt&quot;
    configurations { natives }
    dependencies {
        compile project(&quot;:core&quot;)
        apt &quot;com.squareup.dagger:dagger-compiler:1.2.2&quot;
        compile &quot;com.badlogicgames.gdx:gdx-backend-android:$gdxVersion&quot;
        natives &quot;com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi&quot;
        natives &quot;com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a&quot;
        natives &quot;com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86&quot;
        compile &quot;com.badlogicgames.gdx:gdx-box2d:$gdxVersion&quot;
        natives &quot;com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi&quot;
        natives &quot;com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a&quot;
        natives &quot;com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86&quot;
    }
}

project(&quot;:core&quot;) {
    apply plugin: &quot;java&quot;
    dependencies {
        compile &quot;com.badlogicgames.gdx:gdx:$gdxVersion&quot;
        compile &quot;com.badlogicgames.gdx:gdx-box2d:$gdxVersion&quot;
        compile &quot;com.squareup.dagger:dagger:1.2.2&quot;
        compile &quot;com.squareup.dagger:dagger-compiler:1.2.2&quot;
    }
}

tasks.eclipse.doLast {
    delete &quot;.project&quot;
}&lt;/span&gt;
&lt;/pre&gt;
Next we write the DaggerAdapter - this is the guy that will accept our LIBGDX ApplicationListener and create the Dagger Object Graph:
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;
DaggerAdapter.java
&lt;/span&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;package com.nrg.dagger;

import com.badlogic.gdx.ApplicationListener;

import dagger.ObjectGraph;

public class DaggerAdapter implements ApplicationListener {
    
    private Class applicationListenerClass;
    private ApplicationListener delegateApplicationListener;
    private Object[] daggerModules;
    
    public DaggerAdapter(Class&amp;lt;? extends ApplicationListener&amp;gt; applicationListener,
                         Object... daggerModules){
        this.setApplicationListenerClass(applicationListener);
        this.setDaggerModules(daggerModules);
    }

    @Override
    public void create(){
        final ObjectGraph objectGraph = ObjectGraph.create(this.getDaggerModules());
        final ApplicationListener applicationListener =
                objectGraph.get(this.getInjectableGameClass());
        this.setDelegateApplicationListener(applicationListener);
        this.getDelegateApplicationListener().create();
    }

    @Override
    public void resize(int width, int height) {
        this.getDelegateApplicationListener().resize(width, height);
    }

    @Override
    public void render() {
        this.getDelegateApplicationListener().render();
    }

    @Override
    public void pause() {
        this.getDelegateApplicationListener().pause();
    }

    @Override
    public void resume() {
        this.getDelegateApplicationListener().resume();
    }

    @Override
    public void dispose() {
        this.getDelegateApplicationListener().dispose();
    }
    
    public Class getInjectableGameClass() {
        return applicationListenerClass;
    }

    private void setApplicationListenerClass(Class injectableGameClass) {
        this.applicationListenerClass = injectableGameClass;
    }
    
    private void setDaggerModules(Object[] daggerModules) {
        this.daggerModules = daggerModules;
    }
    
    private Object[] getDaggerModules(){
        return this.daggerModules;
    }

    private ApplicationListener getDelegateApplicationListener() {
        return delegateApplicationListener;
    }

    private void setDelegateApplicationListener(ApplicationListener applicationListener) {
        this.delegateApplicationListener = applicationListener;
    }
}
&lt;/span&gt;
&lt;/pre&gt;
And we&#39;re done! That&#39;s all we need to support Dagger in LIBGDX.&lt;br /&gt;
&lt;br /&gt;
Now let&#39;s see our DaggerAdapter in action. First let&#39;s create a quick injectable GameScreen:
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;
GameScreen.java
&lt;/span&gt;
&lt;/h3&gt;
&lt;pre&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;package com.nrg.example.screens;

import com.badlogic.gdx.Screen;
import javax.inject.Inject;

public class GameScreen implements Screen {

    @Inject
    public GameScreen(){

    }

    @Override
    public void show() {

    }

    @Override
    public void render(float delta) {

      //do game rendering stuff here

    }

    @Override
    public void resize(int width, int height) {

    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void hide() {

    }

    @Override
    public void dispose() {

    }
}
&lt;/span&gt;
&lt;/pre&gt;
&lt;br /&gt;
inject it into our game:

&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;
Main.java
&lt;/span&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;package com.nrg.example;

import com.badlogic.gdx.Game;
import com.nrg.example.screens.GameScreen;
import javax.inject.Inject;

public class Main extends Game {

    @Inject GameScreen gameScreen;

    @Override
    public void create() {
        this.setScreen(gameScreen);
    }

}
&lt;/span&gt;
&lt;/pre&gt;
&lt;br /&gt;
and create the Dagger module:
&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;
GameModule.java
&lt;/span&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;package com.nrg.example.inject;

import com.nrg.example.Main;
import com.nrg.example.screens.GameScreen;
import dagger.Module;

@Module(
        injects = {
            Main.class,
            GameScreen.class
        }
    )
public class GameModule {

}&lt;/span&gt;
&lt;/pre&gt;
&lt;br /&gt;
Now for each of the deployments we simply use the DaggerAdapter instead of the regular LIBGDX ApplicationListener, here&#39;s the one for Android:&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;
AndroidLauncher.java
&lt;/span&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;package com.nrg.example.android;

import android.os.Bundle;

import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.nrg.dagger.DaggerAdapter;
import com.nrg.example.Main;
import com.nrg.example.inject.GameModule;

import dagger.ObjectGraph;

public class AndroidLauncher extends AndroidApplication {
 @Override
 protected void onCreate (Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
         DaggerAdapter daggerAdapter = new DaggerAdapter(Main.class, new GameModule());
         initialize(daggerAdapter, config);
 }
}
&lt;/span&gt;
&lt;/pre&gt;
&lt;br /&gt;
Likewise, here&#39;s the one for the Desktop:&lt;br /&gt;
&lt;h3&gt;
&lt;span style=&quot;color: #0b5394;&quot;&gt;
DesktopLauncher.java
&lt;/span&gt;&lt;/h3&gt;
&lt;pre&gt;&lt;span style=&quot;color: #3d85c6;&quot;&gt;package com.nrg.example.desktop;

import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.nrg.dagger.DaggerAdapter;

import com.nrg.example.Main;
import com.nrg.example.inject.GameModule;

import dagger.ObjectGraph;

public class DesktopLauncher {
 public static void main (String[] arg) {
         final LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
         config.width = 800;
         config.height = 600;
         DaggerAdapter daggerAdapter = new DaggerAdapter(Main.class, new GameModule());
         new LwjglApplication(daggerAdapter, config);
 }
}
&lt;/span&gt;
&lt;/pre&gt;
&lt;br /&gt;
That&#39;s all folks, leave a note if you thought this was helpful.&lt;br /&gt;
&lt;br /&gt;
I&#39;ll be using this in my next game project - currently in the incubation stage ;)</content><link rel='replies' type='application/atom+xml' href='http://javagamedevel.blogspot.com/feeds/7409129364415580255/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javagamedevel.blogspot.com/2015/04/libgdx-dependency-injection-with-dagger.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2897325714589840286/posts/default/7409129364415580255'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2897325714589840286/posts/default/7409129364415580255'/><link rel='alternate' type='text/html' href='http://javagamedevel.blogspot.com/2015/04/libgdx-dependency-injection-with-dagger.html' title='LIBGDX dependency injection with Dagger'/><author><name>Andrew</name><uri>http://www.blogger.com/profile/09635073990556546451</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2897325714589840286.post-1460661903168645440</id><published>2009-11-18T19:07:00.000-08:00</published><updated>2009-11-18T19:07:06.134-08:00</updated><title type='text'>Interlude..</title><content type='html'>Wellllllllll I know I am due for another entry on java game development, but bugger me, I just bought the game &lt;a href=&quot;http://dragonage.bioware.com/&quot;&gt;Dragon Age: Origins&lt;/a&gt;, and damn it looks good. Very good. That and we&#39;re revving up to do some recording for &lt;a href=&quot;http://www.translateband.com/&quot;&gt;my band&lt;/a&gt;, not to mention &lt;a href=&quot;http://www.spacetimeresearch.com/&quot;&gt;my work&lt;/a&gt; is flat out (as always). Might be a week or two before I can spare some time to do a bit more late night programming... it wont happen today, but it will happen.</content><link rel='replies' type='application/atom+xml' href='http://javagamedevel.blogspot.com/feeds/1460661903168645440/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javagamedevel.blogspot.com/2009/11/interlude.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2897325714589840286/posts/default/1460661903168645440'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2897325714589840286/posts/default/1460661903168645440'/><link rel='alternate' type='text/html' href='http://javagamedevel.blogspot.com/2009/11/interlude.html' title='Interlude..'/><author><name>Andrew</name><uri>http://www.blogger.com/profile/09635073990556546451</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2897325714589840286.post-5686388818743711296</id><published>2009-11-12T16:50:00.000-08:00</published><updated>2009-11-16T15:34:14.958-08:00</updated><title type='text'>GWT Java Game Coding Basics: The GameLooper</title><content type='html'>The first class I am going to code for my game is what I am calling the &#39;GameLooper&#39;. The GameLooper will handle a never ending (unless paused) while loop.&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
At this point I&#39;d like to acknowledge the great work by Mark Wilcox at &lt;a href=&quot;http://rebelideas.co.uk/&quot;&gt;Rebel Ideas&lt;/a&gt; who has kindly left his game &quot;&lt;a href=&quot;http://rebelideas.co.uk/games/hothstrike/&quot;&gt;Hoth Strike&lt;/a&gt;&quot; &lt;a href=&quot;http://technorati.com/tag/open-source&quot; rel=&quot;tag&quot;&gt;open source&lt;/a&gt; and un-obsfucated. It saved me a good couple of hours headache around looping.&lt;br /&gt;
&lt;br /&gt;
The &lt;a href=&quot;http://technorati.com/tag/gaming&quot; rel=&quot;tag&quot;&gt;gaming&lt;/a&gt; mechanics will behave much like a television screen, the game looping will calculate if the FPS (frames per second) is too high (not much we can do about low FPS), cap if is it &lt;i&gt;is&lt;/i&gt; too high, and then animate the next frame, rinse and repeat.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s take a look at the code:&lt;br /&gt;
&lt;br /&gt;
&lt;div&gt;package com.blueflame.alienstronghold.client;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;import com.blueflame.alienstronghold.client.ui.ImageAnimator;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;import com.google.gwt.user.client.Timer;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;/**&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;* Creates a never ending game loop and caps the game if if is going too fast.&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;* @author anaish&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;*&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;*/&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;public class GameLooper {&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//ticker timestamp&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;private static long timeStamp;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//should we cap the frame rate?&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;private static boolean capFrameRate;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//frame rate cap amount (ms)&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;private static int capAmount = 42;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//the game timer&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;private static Timer gameTicker;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;/**&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; * Starts the game based on the current keyboard state.&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; * @param keyState the current state of the keyBoard&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; */&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static void startGame(final KeyboardState keyState){&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  //initialise the game ticker to run the loop() method &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;gameTicker = new Timer(){&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;@Override&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;public void run() {&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;loop(keyState);&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;};&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;//start the game in 250 ms&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;gameTicker.schedule(250);&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;ImageAnimator.flashMessage(5,&quot;Ready!&quot;);&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;/**&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; * Loops the game based on the keyboardState&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; * @param keyState the current state of the keyBoard&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; */&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static void loop(final KeyboardState keyState){&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;//cancel the game ticker&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;gameTicker.cancel();&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;//if we&#39;re paused then don&#39;t do anything&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(GameState.isPaused())&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;return;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;//Update the keyboard state&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;ImageAnimator.updateKeyboardState(keyState);&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;//Animate the objects on the screen&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;ImageAnimator.animate();&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;//cap the frame rate if we are going too fast&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;capFrameRate();&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;//re-schedule the never ending loop&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;gameTicker = new Timer(){&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;@Override&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;public void run() {&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;loop(keyState);&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;}&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;};&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(capFrameRate)&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;gameTicker.schedule(capAmount);&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;else&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;gameTicker.schedule(1);&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;/**&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; * Caps the frame rate&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; */&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static void capFrameRate(){&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;capFrameRate = (System.currentTimeMillis() - timeStamp)&amp;lt;capamount;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;timeStamp = System.currentTimeMillis();&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;}&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
The full source code is available &lt;a href=&quot;http://code.google.com/p/alienstronghold/source/browse/trunk/src/com/blueflame/alienstronghold/client/GameLooper.java&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;You&#39;ll see I have made a few references to two other classes ImageAnimator and KeyboardState each responsible for animating objects on the screen and storing the state of the keyboard at any point in time respectively. I&#39;ll be explaining these classes a bit later on.&lt;br /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javagamedevel.blogspot.com/feeds/5686388818743711296/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javagamedevel.blogspot.com/2009/11/gwt-game-coding-basics-gamelooper.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2897325714589840286/posts/default/5686388818743711296'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2897325714589840286/posts/default/5686388818743711296'/><link rel='alternate' type='text/html' href='http://javagamedevel.blogspot.com/2009/11/gwt-game-coding-basics-gamelooper.html' title='GWT Java Game Coding Basics: The GameLooper'/><author><name>Andrew</name><uri>http://www.blogger.com/profile/09635073990556546451</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2897325714589840286.post-8072340658977965547</id><published>2009-11-10T22:35:00.000-08:00</published><updated>2009-11-12T16:43:43.697-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="development"/><category scheme="http://www.blogger.com/atom/ns#" term="gwt"/><category scheme="http://www.blogger.com/atom/ns#" term="ide"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><title type='text'>Planning a GWT Shoot &#39;em up - Part 2</title><content type='html'>OK so I&#39;ve decided pretty much what I want the game to be in &lt;a href=&quot;http://javagamedevel.blogspot.com/2009/11/planning-gwt-shoot-em-up.html&quot;&gt;Part 1&lt;/a&gt;, I expect that some of the details may change as I get in to the nitty gritty of coding, but let&#39;s go with what we have and see what happens, rememer the idea is to do small chuncks of code to get something working, then redesign, rinse and repeat.&lt;br /&gt;&lt;br /&gt;The next part of the planning process I am going to choose the development environment.&lt;br /&gt;&lt;br /&gt;I&#39;ll need:&lt;br /&gt;&lt;br /&gt;- An IDE: My preferred environment is &lt;a href=&quot;http://www.eclipse.org/&quot;&gt;Eclipse&lt;/a&gt; , it&#39;s free, easy to use and is a perfect way to work with the GWT.&lt;br /&gt;&lt;br /&gt;- A source repository: I&#39;ll be making a lot of mistakes, so I&#39;ll get myself a nice source repository to work with so I can roll back my changes at any time. I&#39;ll be using &lt;a href=&quot;http://code.google.com&quot;&gt;Google&#39;s SVN repository&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;- Something to access my source repository with. Although there are ways to integrate Eclipse with SVN, I prefer to use &lt;a href=&quot;http://tortoisesvn.net&quot;&gt;TortoiseSVN&lt;/a&gt;, it does all I need.&lt;br /&gt;&lt;br /&gt;Setting up these three tools are a piece of cake, simply install Eclipse, add the GWT as a plugin and, once you have setup your google code repository, you can link it to Eclipse (using Subversion) or like I do, with TortioseSVN.&lt;br /&gt;&lt;br /&gt;Now we&#39;re ready to start coding.</content><link rel='replies' type='application/atom+xml' href='http://javagamedevel.blogspot.com/feeds/8072340658977965547/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javagamedevel.blogspot.com/2009/11/planning-gwt-shoot-em-up-part-2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2897325714589840286/posts/default/8072340658977965547'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2897325714589840286/posts/default/8072340658977965547'/><link rel='alternate' type='text/html' href='http://javagamedevel.blogspot.com/2009/11/planning-gwt-shoot-em-up-part-2.html' title='Planning a GWT Shoot &#39;em up - Part 2'/><author><name>Andrew</name><uri>http://www.blogger.com/profile/09635073990556546451</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2897325714589840286.post-8043227189552395594</id><published>2009-11-10T19:12:00.000-08:00</published><updated>2009-11-10T22:35:04.638-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="aglie"/><category scheme="http://www.blogger.com/atom/ns#" term="design"/><category scheme="http://www.blogger.com/atom/ns#" term="development"/><category scheme="http://www.blogger.com/atom/ns#" term="game"/><category scheme="http://www.blogger.com/atom/ns#" term="gwt"/><category scheme="http://www.blogger.com/atom/ns#" term="planning"/><title type='text'>Planning a GWT Shoot &#39;em up - Part 1</title><content type='html'>I&#39;d like to take you through some planning behind the first game I will be making with the GWT, tentatively called &quot;Alien Stronghold&quot;. I&#39;ll be using what I&#39;d like to call the Agile++ methodology, which is basically a cut down version of the Agile methodology.. I&#39;ll explain it in another post, but for the moment, think of it like the Agile methodology on steroids.&lt;br /&gt;&lt;br /&gt;Here are some of the project details:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Game type&lt;/strong&gt;: Shoot &#39;em up. I have intentionally stuck to a very simple shoot&#39;em up style game in order to keep the scope as narrow as possible, this will allow me to get something up and going quickly - that&#39;s the essence of an Agile project - get something that works and is demonstrable, and get it done quickly.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Game audience&lt;/strong&gt;: Gamers and coders Age 8+ (I was 12 when I started coding, so you never know!). The idea behind this project is to make something fun and intuitive. It s for people interested in shoot-em ups, but also for those wanting to learn something along the way, and hopefully help other people who may be creating games using the GWT.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Core game features&lt;/strong&gt;:&lt;br /&gt;&lt;br /&gt;- Works on all modern mobile and desktop browsers (IE8, FireFox, Opera, Chrome, Safari)&lt;br /&gt;- Playable online for free and requires no downloads.&lt;br /&gt;- 10 levels, 10 bosses.&lt;br /&gt;- Multiple alien types.&lt;br /&gt;- Fast paced, responsive space ship with cool lasers.&lt;br /&gt;- Top score indicator.&lt;br /&gt;&lt;br /&gt;Now that doesn&#39;t look like much does it? Believe me it is. As a first time game developer I don&#39;t want to bite off too much, I&#39;ll keep the scope short and sweet so I can get a demo out there an working. That way I can continually test and improve it as I go.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Extended game features&lt;/strong&gt;:&lt;br /&gt;&lt;br /&gt;- Save your game at the end of the level&lt;br /&gt;- Introduce currency (Space bucks for blasting aliens!)&lt;br /&gt;- Buy new ships&lt;br /&gt;- Buy Guns&lt;br /&gt;&lt;br /&gt;Although not core features (i.e I&#39;ll do them after we have something up and going) these features will make it more palatable to a wider range of audience, and hopefully get people coming back for more.</content><link rel='replies' type='application/atom+xml' href='http://javagamedevel.blogspot.com/feeds/8043227189552395594/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javagamedevel.blogspot.com/2009/11/planning-gwt-shoot-em-up.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2897325714589840286/posts/default/8043227189552395594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2897325714589840286/posts/default/8043227189552395594'/><link rel='alternate' type='text/html' href='http://javagamedevel.blogspot.com/2009/11/planning-gwt-shoot-em-up.html' title='Planning a GWT Shoot &#39;em up - Part 1'/><author><name>Andrew</name><uri>http://www.blogger.com/profile/09635073990556546451</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2897325714589840286.post-3337138468743736121</id><published>2009-11-10T17:44:00.000-08:00</published><updated>2009-11-12T20:07:21.207-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="BREW"/><category scheme="http://www.blogger.com/atom/ns#" term="development"/><category scheme="http://www.blogger.com/atom/ns#" term="game"/><category scheme="http://www.blogger.com/atom/ns#" term="gwt"/><category scheme="http://www.blogger.com/atom/ns#" term="java"/><category scheme="http://www.blogger.com/atom/ns#" term="MIDP"/><title type='text'>Mobile java game development becomes viable.</title><content type='html'>I&#39;ve been &lt;a href=&quot;http://technorati.com/tag/software-engineering&quot; rel=&quot;tag&quot;&gt;software engineering&lt;/a&gt; as Java Developer for nearly fifteen years, during that time I&#39;ve been mainly coding corporate back end server side systems - things like call center applications, content management systems and web data dissemination platforms - which, I must admit, has paid the bills and allowed me to learn new technologies along the way. I&#39;ve also been lucky enough to code a few mobile apps - some in BREW (http://brew.qualcomm.com) and others using MIDP (http://java.sun.com/products/midp).&lt;br /&gt;
&lt;br /&gt;
However, I&#39;ve always had a passion for games, love playing them, would love to develop them. There&#39;s a few problems with my situation though, and I suspect there&#39;s plenty of other Java developers out there with the same issues - &lt;span style=&quot;font-style:italic;&quot;&gt;no one makes games (mobile or desktop) with Java&lt;/span&gt;. Why? &lt;br /&gt;
&lt;br /&gt;
- Games must perform to be viable. Currently here is a perception that Java is slower than C/C++. Of course this is not true in all circumstances, it highly depends on implementation, but the perception is there, has been there since Java became mainstream, and seems to be sticking. The preferred language for games is C/C++ (or a derivative thereof).&lt;br /&gt;
&lt;br /&gt;
- Java&#39;s &quot;write once, run anywhere&quot; just isn&#39;t true, especially for mobile devices. Handset manufactures seemed to have almost made an striving effort to diverge from the (many) standards for mobile devices, I know - I&#39;ve tried writing (rather simple) applications and porting them to different devices, it&#39;s not fun. At all.&lt;br /&gt;
&lt;br /&gt;
- The &lt;a href=&quot;http://technorati.com/tag/iphone&quot; rel=&quot;tag&quot;&gt;iphone&lt;/a&gt; is currently king of the mobile app market, and it doesn&#39;t support a JVM (unless you jailbreak it).&lt;br /&gt;
&lt;br /&gt;
- Most mobile application hosting is expensive and difficult to access.&lt;br /&gt;
&lt;br /&gt;
So I&#39;d like to propose an alternative.&lt;br /&gt;
&lt;br /&gt;
The alternative will:&lt;br /&gt;
&lt;br /&gt;
- Allow you to code decent games in your favorite language (Java) for &lt;a href=&quot;http://technorati.com/tag/mobile-devices&quot; rel=&quot;tag&quot;&gt;mobile devices&lt;/a&gt;.&lt;br /&gt;
- Will run on most mobile platforms (including the IPhone) with the added benefit of any (modern) browser you like.&lt;br /&gt;
- Allow you to host your games online for free.&lt;br /&gt;
&lt;br /&gt;
You guessed it - the GWT (http://code.google.com/webtoolkit/)&lt;br /&gt;
&lt;br /&gt;
Google&#39;s GWT has it all - Java to JavaScript compiler, persistence, authentication, code optimisation and obfuscation, cross-browser compatibility + more. It&#39;s all there.&lt;br /&gt;
&lt;br /&gt;
Now I admit you&#39;re not going to be able to develop World of Warcraft for the IPhone with the GWT, however I promise you, as a Java developer will be able to start moving out of those dark server rooms and onto the client to make something fun and viable.&lt;br /&gt;
&lt;br /&gt;
Ive started coding a simple shoot&#39;em up using the GWT, and I must admin I am very impressed. I&#39;ll be taking some time to show you the code once I&#39;m ready.</content><link rel='replies' type='application/atom+xml' href='http://javagamedevel.blogspot.com/feeds/3337138468743736121/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javagamedevel.blogspot.com/2009/11/mobile-java-game-development-becomes.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2897325714589840286/posts/default/3337138468743736121'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2897325714589840286/posts/default/3337138468743736121'/><link rel='alternate' type='text/html' href='http://javagamedevel.blogspot.com/2009/11/mobile-java-game-development-becomes.html' title='Mobile java game development becomes viable.'/><author><name>Andrew</name><uri>http://www.blogger.com/profile/09635073990556546451</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>