There are many game engines available for mobile platforms like:-
1 AndEngine.(2D Only)
2 Cocos2d.(2D Only)
3 Min3d.(3D)
4.jMonkey(3D)
..etc
But most programmers prefer libgdx due to following advantages:-
1. Open source.
2. Supports 2D and 3D(3D is still Updating with new features).
3. Free since it is open source.
4. Many sample tutorials available on home site of libgdx.
5. Supports various platforms(Android/ios/Html5/Desktop).
So here we will learn to simply configure our libgdx project and write our first libgdx program.
*Assuming you have some basic knowledge of programming before.
(SYSTEM SETUP)
Steps involved :-
1 Install java development toolkit (jdk). here.
2 Download and extract Android SDK (ADT Bundle) from here.
*what is difference between both libraries?
:-
There is nothing much difference you can choose any - Release build is updated only when considerable changes are done while nightly build is updated almost daily.
4 Unzip the contents of library in some directory (say:- c:\game_engine\libgdx).
(PROJECT SETUP)
(Main base project can be used in android,desktop,html5 project)
1. Open Eclipse come with ADT Bundle.
2. Create a new java project.(name: mylibgdx).
3. Create a package in src folder(com.suheb.libgdx_example).
4. Create a class in this package (mylibgdx_class).
5. Now we have to import libgdx libraries.
1> Right click on project folder and go to build path->configure build path.
2> Select "Add External JARs".
3> Browse to location where you have extracted libgdx libraries (say:- c:\game_engine\libgdx).
and select these jars:-
1.gdx.jar
2.gdx-natives.jar
3.gdx-backend-lwjgl.jar
4.gdx-backend-lwjgl-natives.jar
click ok.
6. Now open our class (mylibgdx_class) implements it with ApplicationListener.
7. Press ctrl+shift+o and all unimplemented methods will auto generated.
OR
You can type/copy the following code as it is in your class.
//CODE
package com.suheb.libgdx_example;
import com.badlogic.gdx.ApplicationListener;
public class mylibgdx_class 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() {
// TODO Auto-generated method stub
}
@Override
public void resize(int arg0, int arg1) {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
}
I am not describing whole code skeleton right now
Just a quick description....
- create method :- Called when project executes and its instance is created mostly all initializations and variables goes here.
- dispose :- when program is going to terminated.releasing of resource goes here.
- pause :- when when program is paused or is not in focus all rendering and screen updates should also be paused.
- render :- called repeatedly all updation to screen goes here.
- re-size :-called when screen size is changed or orientation is changed.
- resume :- called after pause is removed.all rendering and updation also resumes.
Desktop project:-
- Create a new Java project in Eclipse.
- Project name-mylibgdx_desktop.
- Right click project folder and create a new folder named "libs". copy following jars in that folder
- gdx-natives.jar
- gdx-backend-lwjgl.jar
- gdx-backend-lwjgl-natives.jar
- In Eclipse, right click the project -> Refresh. Right click again -> Properties -> Java Build Path -> Libraries -> Add JARs, select the three JARs and click OK.
- Click the Projects tab, click Add, check the main project and click OK.
Android project:-
- Create a new Android project in Eclipse.
- Project name-mylibgdx_android.
- Build target android 1.5 or more.
- Package name - com.suheb.libgdx_example_android then click Next.
- Create activity MyLibgdx_Example_Android.
- Right click project folder and create a new folder named "libs". copy following jars in that folder
- gdx-backend-android.jar
- gdx.jar
- both armeabi and armeabi-v7a folders.
- In Eclipse, right click the project -> Refresh. Right click again -> Properties -> Java Build Path -> Libraries -> Add JARs, select gdx-backend-android.jar and gdx.jar click OK.
- Click the Projects tab, click Add, select the mylibgdx project and click OK twice.
- Click the Order and Export tab, check the mylibgdx project.
Run project on desktop
Right click the desktop project -> New -> Class. Name it Desktop_Sample and specify a package (eg, "com.suheb.desktop_example"). Use following code:
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
public class Desktop_Sample{
public static void main (String[] args) {
new LwjglApplication(new mylibgdx_class(), "My_Libgdx_Example", 480, 320, false);
}
}
This code creates an LwjglApplication, gives it an instance of your class, a title, and size. The "false" means we aren't using OpenGL ES 2.0 (we will use 1.0/1.1).
To run the game on the desktop, right click the project -> Debug As -> Java Application. You should get a black window titled "My_Libgdx_Example".
Run project on Android
Open the MyLibgdx_Example_Android class in the Android project that was automatically created and make it look like this:
import com.badlogic.gdx.backends.android.AndroidApplication;
public class MyLibgdx_Example_Android extends AndroidApplication {
public void onCreate (android.os.Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initialize(new Game(), false);
}
}
I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have bookmarked your web site to check out the latest stuff you post.
ReplyDeleteMobile Application Development Company
Thanks for sharing your view on this.I am glad it helps you.
ReplyDeleteExcellent information, thanks for sharing great information. We deal with Android Game Development this information is quite unique and interesting.
ReplyDeleteThe article posted was very informative and useful. You people are doing a great job. Keep going.
ReplyDeleteWeb Design In Houston
confusing ;( Thank You.
ReplyDeleteOne of the best article to getting more knowledge information, thanks for shared and enjoyed to reading this post.
ReplyDeletegame app developer