Prepare the source code
Previously, we
created the project gdx-hello using both the manual method and the other
with a tool implementation.
Now you are ready for your first
application
Go to the Desktop
project gdx-hello and create a new class called game in a new
package called my.works.jeux, the content of the game class will be as the
following :
package my.works.game;
import
com.badlogic.gdx.ApplicationListener;
public class Game
implements
ApplicationListener {
@Override
public void
create() {
//
TODO Auto-generated method stub
}
@Override
public void
dispose() {
//
TODO Auto-generated method stub
}
@Override
public void
pause() {
//
TODO Auto-generated method stub
}
@Override
public void
render() {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
Gdx.gl.glClearColor(0,
1, 0, 1);
}
@Override
public void
resize(int arg0, int
arg1) {
//
TODO Auto-generated method stub
}
@Override
public void
resume() {
//
TODO Auto-generated method stub
}
}
This source code
is only for make the screen color green.
Create another
class in the project gdx-hello we called this class DesktopLauncher
and whose content is :
package my.works.game;
import com.badlogic.gdx.backends.jogl.JoglApplication;
public class DesktopLauncher
{
public static void
main(String[] args) {
new JoglApplication (new Game(),"Game title",480,320,false);
}
}
Now, make the
class main on the gdx-helloAndroid Project look like this:
package
my.works.GdxhelloAndroid;
import my.works.game.Game;
import
com.badlogic.gdx.backends.android.AndroidApplication;
import
android.os.Bundle;
public class
main extends AndroidApplication {
/**
Called when the activity is first created. */
@Override
public void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initialize(new Game(), false);
}
}
If you run the
first project ( gdx-hello ) you will see this screen:
If you run the
second project ( gdx-helloAndroid ) on your emulator you will see this:
To sum things up
here is what we did :
Congratulations !
This is your first apps but not your first great useful apps.
You can download
the exported project gdx-hello
Problems ?
If you have any comments or questions please post them in the comments section . Thank you for reading.
See also !
No comments:
Post a Comment