Posted on

List of Open Source Game Engine for Android

Open Source Game Engine for Android

List of Open Source Game Engine for Android Platform

Open Source Game Engine for Android
Open Source Game Engine for Android

Summary:

In this article i am going to tell you about 3 open source game engine which i have used to make Games / Live Wallpaper for android platform.

 

Game Engine Language Platforms 2D/3D Live Wallpaper
Cocos2d-x C++,LUA,JS-Binding Android,IOS,Mac,Linux,Win32 others 2D + 3D (50% Features as Compared to LibGDX)

No

LibGDX Java Windows, Mac, Linux, Android, IOS, BlackBerry and HTML5 2D + 3D Yes
AndEngine Java Android 2D Yes

History Cocos2d-x  (Updated)

Language: C++

Details
Cocos2d-x is a very powerfull engine to create Games & Apps for cross platforms.It comes with editor like CocoStudio which contains Animation Editor,GUI Editor and other tools
Some games which are created with Cocos2d-x are BadLand,Hill Climb Racing.The 3D support is not completed there are some features for 3D like loading 3D FBX models,Texturing but advance features has not yet implemented.
It also comes with win32 version so if you are working on desktop you can use it in Visual studio and test.

Support: Coocs2d-x community is consist of active members which can help if you come with any error just post on their forum.

History LibGDX (Updated)

Language: C++ is used for performance but you will write the code in JAVA which will be used with NDK (Native Development Kit)

Details
LibGDX is a good engine which can be used for creating games ,apps & live wallpaper.It has a full 3D Support from loaidng model to textures and 3D physics engine.You can use it to make baics to advance 3D Games.,
It also comes with a desktop version so if you are creating it on desktop ,you can run & test it for fast developing.Games created using LibGDX are Five Nights at Freddy’s

Support:LibGDX also has a forum for members but active members are less then Cocos2d-x

History AndEngine (Outdated)

Language: It uses same technology as LibGDX C++ for performance in NDK and JAVA Wrapper for you to use the JAVA code

Details
AndEngine is used for 2D Games you will not be able to create 3D games in AndEngine.You can use it for Games,Apps,Wallpapers.

Support: Same as LibGDX active members are less so the chances of getting help is less then the Cocos2d-x Forum.

How to chose best open source game engine ?

It depends upon you what language,what style you like to work with.

My personal choice is Cocos2d-x as i have used it to create Rickshaw Racer and i found it interesting to work. I have also used LibGDX but for Live Wallpaper Wizard Times

Learn one game engine and you can follow the logic with other because the Logic for creating sprites is same. Physics engine is same if you are going to use Box2D ,just Programming language is different if you know JAVA then i would suggest go for LibGDX or AndEngine else if you know C++ then Cocos2d-x is the best choice.

Sample link for the features ,Use it ,Test it & Choose It

Cocos2d-x: https://github.com/cocos2d/cocos2d-x/tree/v3/tests/cpp-tests (It’s a GitHub Directory so you have to download it and install it with Cocos2d-x Code) (Updated)

LibGDX: https://github.com/libgdx/libgdx/tree/master/tests (Updated)

AndEngine: https://github.com/nicolasgramlich/AndEngine (Outdated)

 

Official Website Link:

Cocos2d-x –http://cocos2d-x.org/

LibGDX- https://libgdx.badlogicgames.com

AndEngine- http://www.andengine.org/

 

(Updated) = Updated Regulary and supported with developers

(Outdated)= Outdated not updated for more then 1 year.

 

Note: If you would like to list your Open Source game engine then please let us know in comments

 

Posted on

Tutorial 2 : Connect Android with PHP,MySQL (JAVA Code)

Fetched Data by Tutorial Connect

Welcome to Connect Android with PHP & MySQL Series Part 2

Summary

In this tutorial i will show you how to access the fetched data from PHP Script using Volley Library,Parse the fetched JSON and show it in ListView

0.) Requirement

To test the communication between WAMP and your android app you must be on same network.For eg. you are connected to same Wireless router on your device and with your computer on which WAMP is running.

1.) Setting up Required Libraries (Volley Library)

Download volley library from here

Add the downloaded jar file to project
Create a new Project in Eclipse File -> New -> Android Application Project -> Fill the required fields.
once the project is succesfully created paste the volley.jar in libs folder (if there is no libs folder then you can make one)

2.) Starting Project

Creating Volley Applicatio class this class will maintain volley objects & request queue.
In your project create a new class named VolleyController.java & extend the class from Application & add following code
VolleyController.java

package com.developerhouse.android.connect;
import android.app.Application;
import android.text.TextUtils;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;
public class VolleyController extends Application {
public static final String TAG_APP = VolleyController.class
.getSimpleName();
private RequestQueue requestQueue;
private ImageLoader imageLoader;
private static VolleyController instance;
@Override
public void onCreate() {
super.onCreate();
instance = this;
}
public static synchronized VolleyController getInstance() {
return instance;
}
public RequestQueue getRequestQueue() {
if (requestQueue == null) {
requestQueue = Volley.newRequestQueue(getApplicationContext());
}
return requestQueue;
}
public ImageLoader getImageLoader() {
getRequestQueue();
if (imageLoader == null) {
imageLoader = new ImageLoader(this.requestQueue,
new LruBitmapCache());
}
return this.imageLoader;
}
public <T> void addToRequestQueue(Request<T> req, String tag) {
req.setTag(TextUtils.isEmpty(tag) ? TAG_APP : tag);
getRequestQueue().add(req);
}
public <T> void addToRequestQueue(Request<T> req) {
req.setTag(TAG_APP);
getRequestQueue().add(req);
}
public void cancelPendingRequests(Object tag) {
if (requestQueue != null) {
requestQueue.cancelAll(tag);
}
}
}

LruBitmapCache.java

package com.developerhouse.android.connect;
import com.android.volley.toolbox.ImageLoader.ImageCache;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
public class LruBitmapCache extends LruCache<String, Bitmap> implements
ImageCache {
public static int getDefaultLruCacheSize() {
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
final int cacheSize = maxMemory / 8;
return cacheSize;
}
public LruBitmapCache() {
this(getDefaultLruCacheSize());
}
public LruBitmapCache(int sizeInKiloBytes) {
super(sizeInKiloBytes);
}
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight() / 1024;
}
@Override
public Bitmap getBitmap(String url) {
return get(url);
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
put(url, bitmap);
}
}
&nbsp;

Edit AndroidManifest.xml file and add the VolleyController class in <application> tag using android:name
this will execute the class automatically when the app launch & add INTERNET permission because we need to call web services.
AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.developerhouse.android.connect"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="22" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name="com.developerhouse.android.connect.VolleyController"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

We are outputting JSON array from php Script in JSON if the starting tag is [ then it’s a Array else if it is { then it’s a Object

Json Array (Current output)

[{"id":"1","title":"Rickshaw Racer","description":"Get Rickshaw Racer on Google Play","img_url":"http:\/\/s22.postimg.org\/kg4dj2usx\/Icon_Rickshaw_512.png"}]

Json Object

{"id":"1","title":"Rickshaw Racer","description":"Get Rickshaw Racer on Google Play","img_url":"http:\/\/s22.postimg.org\/kg4dj2usx\/Icon_Rickshaw_512.png"}

MainActivity.java

package com.developerhouse.android.connect;
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.JsonArrayRequest;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
public class MainActivity extends Activity { 
private ProgressDialog dialog=null ;
private String TAG="Tutorial Connect";
private String tag_json_arry = "json_array_req";
private String url = "http://192.168.1.5";
private String url_file="/fetch.php";
private CustomAdapter adapter;
private ListView list;ArrayList<RowData> rowdata;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list=(ListView) findViewById(R.id.listView1);
rowdata=new ArrayList<RowData>();
dialog= new ProgressDialog(this);
dialog.setMessage("Loading...");
dialog.show();
JsonArrayRequest request = new JsonArrayRequest(url+url_file,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d(TAG, response.toString()); try {
for(int i=0;i<response.length();i++){
String title=response.getJSONObject(i).getString("title");
String description=response.getJSONObject(i).getString("description");
String img_url;
img_url = response.getJSONObject(i).getString("img_url");
rowdata.add(new RowData(title, description, img_url));
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
adapter=new CustomAdapter(MainActivity.this, rowdata);
list.setAdapter(adapter);
dialog.dismiss();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, "Error: " + error.getMessage());
dialog.dismiss();
}
});
// Adding request to request queue
VolleyController.getInstance().addToRequestQueue(request, tag_json_arry);
}
}

Line 22

private String url = "http://192.168.1.5";

Change this to the IP of your computer

How to get IP of the computer ?

Open CMD type ipconfig you will see something like this

How to use IPConfig
How to use IPConfig

check your default Network Adapter IP

the above code will Log the response & show fetched data in ListView so fire up WAMP ,check PHP Script it’s fetching result or not & run your android app if it output something in LogCat then you are good to continue else post the Error in Comment section or search it on Google

 

CustomAdapter.java

this class is Custom Adapter which will fill be filled by listview

package com.developerhouse.android.connect;
import java.util.ArrayList;
import com.android.volley.toolbox.NetworkImageView;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class CustomAdapter extends BaseAdapter{
private ArrayList<RowData> result;
private Context context;
private static LayoutInflater inflater=null;
public CustomAdapter(MainActivity mainActivity, ArrayList<RowData> data) {
// TODO Auto-generated constructor stub
result=data;
context=mainActivity;
inflater = ( LayoutInflater )context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return result.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public class Holder
{
TextView title;
TextView description;
NetworkImageView img;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Holder holder=new Holder();
View rowView;
rowView = inflater.inflate(R.layout.list_item, null);
holder.title=(TextView) rowView.findViewById(R.id.textView1);
holder.description=(TextView) rowView.findViewById(R.id.textView2);
holder.img=(NetworkImageView) rowView.findViewById(R.id.networkImageView);
holder.title.setText(result.get(position).getTitle());
holder.description.setText(result.get(position).getDescription());
// If you are using NetworkImageView
holder.img.setImageUrl(result.get(position).getImageURL(), VolleyController.getInstance().getImageLoader()); 
return rowView;
}
}

RowData.java

this class contains variable to hold list item data which is Title,Description,Image Url

package com.developerhouse.android.connect;
public class RowData {
private String title;
private String description;
private String img_url;
public RowData(String title,String description,String img_url){
this.title=title;
this.description=description;
this.img_url=img_url;
}
public String getTitle(){
return title;
}
public String getDescription(){
return description;
}
public String getImageURL(){
return img_url;
}
}

 

XML Layout

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.developerhouse.android.connect.MainActivity"
android:orientation="vertical">
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>

list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.android.volley.toolbox.NetworkImageView
android:id="@+id/networkImageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerHorizontal="false" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/networkImageView"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/networkImageView"
android:layout_below="@+id/textView1"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>

Fetched data will show like this

Fetched Data by Tutorial Connect
Fetched Data by Tutorial Connect
Posted on

Tutorial 1 : Connect Android with PHP,MySQL (PHP Code)

Welcome to Connect Android with PHP & Mysql Series Part 1

Summary

In this tutorial i will show you how to create database, get data from PHP scripts & show it in json form which you access by a URL.

1.) Installing Wamp Server on Windows.

Go to http://www.wampserver.com/en/ download the Wamp as per your software architecture 64 bit or 32 bit

Wamp Folder
Wamp Folder

Then go to install location mine is C:\wamp (by default this is the install location for are users) open wampmanager.exe

Now you can test your wamp server by going to this address in browser http://localhost/ or http://127.0.0.1. If it’s opening default page of wamp then you’re good to proceed further.

Check the phpmyadmin also with the url : http://localhost/phpmyadmin (PHPMyAdmin helps us to create,manage,insert into the database,tables with Graphical User interface instead of MySQL Console window)

2.) Creating our first PHP Script to test

Open notepad or notepad++ (i am using Notepad++)

write this code

<?php
echo "Hello,World";
?>

<?php means opening tag for any PHP Script it’s like public class name { in java

and ?> means closing tag like closing bracket in JAVA

what ever you code write in these tag will be handle as PHP code

echo means System.out.println

Save it as test.php in c:\wamp\www (all files in this folder will be accessible from localhost)

now when you access it with this URL http://localhost/test.php it will print this Hello,World

Hello-World
Hello-World

3. )Let’s move to create database through PHPMYADMIN

open this http://localhost/phpmyadmin

Click on Database button on top header now it will take you to create database page

Localhost PHPMyAdmin
Localhost PHPMyAdmin

Enter DB (Database) name in first text box and create on create.

Create Database in PHPMyAdmin
Create Database

Now on left sidebar you will see list of database.Click on your newly created database then click on Create Table.

Create Table in PHPMyAdmin
Create Table

Fill fields

  1. Table Name : products
  2. No. of columns : 4

Columns

Products Table
Products Table
Name Type Length/Values A I (Auto Increment)
id INT Empty (By Default) Yes
title VARCHAR 40 No (By Default)
description VARCHAR 250 No (By Default)
img_url VARCHAR 100 No (By Default)

Now we will add a entry in MySQL Table named products

Select products from side panel.Click on Insert on Header

Now fill it like this

Column Type Function Value
id INT(11)
title VARCHAR(40) Rickshaw Racer
description VARCHAR(250) Get Rickshaw Racer on Google Play
img_url VARCHAR(100) http://s22.postimg.org/kg4dj2usx/Icon_Rickshaw_512.png

Now you have filled it with details click on Go Button.

Insert 1 or  more rows with the details you want to be shown in Android App.

4.) Move to PHP again to show our data by echo command

Let’s make a config.php file in the www folder in wamp directory.

Detail about config.php : It’s usefull to save all the MySQL database info in one file so you don’t have to fill it again & again.

  • Host = localhost (by default if you’re using it on wamp and MySQL Server is also installed on same machine)
  • Username = root (by default)
  • Password =  (by default Empty 0 length)
  • Database name = android_db (same)
  • Table name = products (same)
<?php
$host="localhost";
$user_name="root";
$password="";
$db_name="android_db";
$table_name="products";
//Let's make a mysql connection to connect the server.
$con=mysqli_connect($host,$user_name,$password);
mysqli_select_db($con,$db_name);
?>

Explanation by lines

1.) Opening Tag.

2.) Host name or Ip Address where our MySQL Server is installed.

3.) Username to access the database.

4.) Password for the username to get pass authentication.

5.) Database name in our case android_db which we made in earlier steps.

6.) Table name in our case products

8.) Comment just like we do in JAVA

9.) It’s connecting to MySQL Database to make communication

10.) Select database to communicate

5.) Create fetch.php to get results from table

Code

<?php
include_once("config.php");
$query=mysqli_query($con,"SELECT * FROM ".$table_name);
$array;
while($result=mysqli_fetch_assoc($query)){
$array[]=$result;
}
echo json_encode($array);
?>

Explanation by lines

2.) Include config.php just like Import in Java.

4.) Here we query the MySQL Database to give us all rows from table name

5.) Declaring array as a variable

6.) While Loop to fetch all results

8.)The $result fill all results in $array

11.) Print encoded JSON

try to access the file via Browser from this url http://localhost/fetch.php it will print something like this

[{"id":"1","title":"Rickshaw Racer","description":"Get Rickshaw Racer on Google Play","img_url":"http:\/\/s22.postimg.org\/kg4dj2usx\/Icon_Rickshaw_512.png"}]

So the PHP Part is completed in next Tutorial we will work on Android Code

Posted on

Android App Tutorial Series Connect with PHP,MySQL

Web Services Diagram

Android App Tutorial Series

In this Series of android app tutorial we will focus on how to connect with PHP Scripts with MySQL as database and communicating with android.

Basically it is used as Web Services for fetching,inserting,managing data through android app with the help of PHP Scripts.

We will call the PHP Script with Volley Library (Saves time,Easy to use)

So the operation will be simple as defined in below image

Web Services Diagram
Web Services Diagram

your code calls PHP script

 

What is PHP ?

PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language

What is MySQL ?

With PHP, you can connect to and manipulate databases.

MySQL is the most popular database system used with PHP

How to host files of PHP & MySQL (It’s not same as putting *.java files in your Project) ?

You need a hosting if  you want to access it over Internet

OR

You can use WAMP,XAMPP or any other server on your computer install one of them by this you can host your PHP files locally and access it via 127.0.0.1 or localhost (these are the address to access your files just like domain name developerhouse.com)

PHP script will work on Server Side for inserting, Editing, Deleting ,Showing Records with MySQL Database.

I’ll be using Hostgator shared hosting to host PHP Scripts.if you want to use any other hosting the process will be same if the hosting provides CPanel.

OR

I will also post Screenshot to get you started with WAMP so that you ca use localhost instead of Linux Hosting (WAMP,XAMPP)

Tutorial List:

Part 1- Tutorial 1 : Connect Android with PHP,MySQL (PHP Code)

Part 2- Tutorial 2 : Connect Android with PHP,MySQL (JAVA Code)