Pages

Subscribe:

Ads 468x60px

Cocos2d-Android game Development

Developing game is a real fun. Recently I was working with cocos2d-android engine. I think it’s a very cool game developing engine. In this text I will introduce you to the essential building block of cocos2d-android game engine.
The Cocos2d Scene
A scene is a more or less independent piece of game workflow. You may call it screen or stage. Your game may have multiple scenes. For example – Splash screen, Menu, Level, High scores screen etc. Scene is implemented by CCScene class.
In the most cases CCScene doesn’t contain any game specific code and is rarely sub-classed. Normally it holds children which are derived from CCLayer which contain in turn contain the individual game objects. Most often Scene is created inside CCLayer Object in a static method

Director
The director is the component which takes care about going back and forth between scenes. The Director is a shared object. It is implemented singleton. It knows everything, like which scene is currently active etc. More generally it holds stack of scene. Any replacement of scene is made by Director. It is implemented by CCDirector class

Layer
Sometimes you need more than one layer in your scene. In that case you can add more CCLayer object to your scene. It helps you organize the scene. For example – background, top, bottom etc. Layers are basically a grouping concept. Some layers- CCLayer: very basic layer of cocos2d.
CCColorLayer: A solid color rectangle, it works as CCLayer but only contains a background color.
CCMultiplexLayer: A group of layers where only one is seen at a time.
CCMenu: Implemets simple menu


Sprite
A cocos2d sprite is like any other computer sprite. It is a 2D image that can be moved, rotated, scaled, animated etc. CCSprite is implementation of it. It can have other sprite as children. When parent is transformed, all the other children are transformed as well. Creating a sprite is very simple. You have to add the image file to the asset folder of your project. And the code is very straight forward

3D Android Game Engines

• Untity3D 3.0
unity3d

•Airplay SDK 4.2
Airplay

• ShiVa3D (Beta Version)
ShiVa3D

•DX Studio
DX Studio

• Angekündigt: Unreal Development Kit (Unreal Engine 3)
Unreal Engine



Simple tutorial for using e3roid 2D OpenGL framework for Android

First we need to install e3roid game framework. Download the latest e3roid source distribution(e3roid-source-X.X.zip) from Google code project page and unzip it to appropriate directory. After the preparations let's create a new Android Application. At first we need a new Activity which extends the E3Activity to declare using e3roid framework. This is the base activity class of the engine.

    public class OpenGLDemoActivity extends E3Activity
    {
        ...
    }

In the onCreate() method we detect the display parameters of the mobile device because the width and height values needed to create the game engine.
    @Override
    protected void onCreate( Bundle savedInstanceState )
    {
            Display display = getWindowManager().getDefaultDisplay();
            width = display.getWidth();
            height = display.getHeight();
     
            super.onCreate( savedInstanceState );
    }

The E3Engine a base engine for the framework that is responsible for rendering.

    @Override
    public E3Engine onLoadEngine()
    {
            E3Engine engine = new E3Engine( this, width, height );
            engine.requestFullScreen();
            engine.requestPortrait();
            return engine;
    }


After initializing e3roid engine by overriding onLoadEngine(), we can add resources (sprite, shape, etc) by overriding onLoadResources(). The example shows how to instantiate the textures. If we use AssetTexture class, images must be saved into the “assets” folder. Transparent PNG image can be used if the sprite needs transparency. Transparent GIF image is currently not supported.

    @Override
    public void onLoadResources()
    {
            //texture for the droid
            robotTexture = new AssetTexture( "gfx/droid.png", this );
            //background's texture
            Bitmap tile = BitmapUtil.getTileBitmapFromAsset(
                    "gfx/bg.png", 64, 64, 0, 0, 0, this );
    }

After initializing sprites, we can create e3roid’s “scene” and move the robot sprite into the scene. The scene width and height can be obtained by calling getWidth and getHeight. The example shows how to instantiate and add on center of the screen the sprite. After moving sprites, we must “add” the sprite to the scene.

    @Override
    public E3Scene onLoadScene()
    {
            E3Scene scene = new E3Scene();
            scene.addEventListener( this );
     
            Background background = new Background(
                    tile, getWidth(), getHeight(), this );
            scene.getTopLayer().setBackground( background );
     
            int centerX = (getWidth() - robotTexture.getWidth()) / 2;
            int centerY = (getHeight() - robotTexture.getHeight()) / 2;
     
            robot = new Sprite( robotTexture, centerX, centerY );
            scene.getTopLayer().add( robot );
            Toast.makeText(
                    this, "Touch screen to move the sprite.", Toast.LENGTH_LONG )
            .show();
     
            return scene;
    }

To handle user’s interactions, add event listener to the scene first. By adding listener to the scene, the onSceneTouchEvent method will be called when user touches the screen.
    @Override
    public E3Scene onLoadScene()
    {
            E3Scene scene = new E3Scene();
            scene.addEventListener( this );
            // snip ...
    }


And then override onSceneTouchEvent method and implement it like below. The example below moves the sprite on the center of the touched position. Remember that the location we can get from motion event(getX,getY) is the actual device’s raw pointer location. To adjust the coordinates that fit with the screen size defined in the E3Engine’s constructor, use getTouchEventX and getTouchEventY method.
    @Override
    public boolean onSceneTouchEvent( E3Scene scene, MotionEvent motionEvent )
    {
            if( robot != null )
            {
                    if( motionEvent.getAction() == MotionEvent.ACTION_DOWN )
                    {
                            int x = getTouchEventX( scene, motionEvent ) -
                                      (robotTexture.getWidth() / 2);
                            int y = getTouchEventY( scene, motionEvent ) -
                                      (robotTexture.getHeight() / 2);
                            robot.move( x, y );
                    }
            }
            return false;
    }

The result should look like this:

Make Big Money Selling Android Apps

Discover How To Build And Successfully Market Android Apps With Our 150+ Page Guide. No Previous Programming Skills Required. Plus Buyers Receive A Fully Functional Gaming App To Re-brand And Re-sell Worth Over $1000. Sell With Ease!

Click Here!

18 Pages To Become An Android Expert

We Have Simplified The Learning Curve For All Android Devices. This 18 Page E-book Will Teach You What You Need To Know To Be Fast And Efficient At The Android Phones And Pads
Click Here!

How to create a basic splashscreen for your Android games

The following code will show you how to create a basic splashscreen for your Android games that will stay for 5 seconds. If we don't want to wait we can tap the screen to go directly to the next Activity. Source project is on the bottom of the tutorial.

The project has:
2 Activities
1 Image
0 Animations

Lets go through the code to see how simple it is to make a very basic splash screen for your application.
The splashscreen will be the startup Activity for our application and on application launch a Thread will start that will listen for touch events.

public class SplashScreen extends Activity {
02  
03     //how long until we go to the next activity
04     protected int _splashTime = 5000;
05  
06     private Thread splashTread;
07  
08     /** Called when the activity is first created. */
09     @Override
10     public void onCreate(Bundle savedInstanceState) {
11         super.onCreate(savedInstanceState);
12         setContentView(R.layout.splash);
13  
14         final SplashScreen sPlashScreen = this;
15  
16         // thread for displaying the SplashScreen
17         splashTread = new Thread() {
18             @Override
19             public void run() {
20                 try {
21                     synchronized(this){
22  
23                         //wait 5 sec
24                         wait(_splashTime);
25                     }
26  
27                 } catch(InterruptedException e) {}
28                 finally {
29                     finish();
30  
31                     //start a new activity
32                     Intent i = new Intent();
33                     i.setClass(sPlashScreen, Main.class);
34                     startActivity(i);
35  
36                     stop();
37                 }
38             }
39         };
40  
41         splashTread.start();
42     }
43  
44     //Function that will handle the touch
45     @Override
46     public boolean onTouchEvent(MotionEvent event) {
47         if (event.getAction() == MotionEvent.ACTION_DOWN) {
48             synchronized(splashTread){
49                 splashTread.notifyAll();
50             }
51         }
52         return true;
53     }
54  
55 }

To get a better understanding on how this project works just download the source code

Install Android Games for Your PC

Up until recently there has not been a reliable source for playing Android games on your PC. Fortunately, as Android technology becomes more widespread in phones, laptops, netbooks, and tablets, the demand for Android software has dramatically increased. This increase in demand has led to the development of several Android emulators for your PC
There are a few different types of Android emulators at this point, and Android Emulators For PC outlines the pros and cons of each one. Their tutorial video for how to install Android-x86 in less than 5 minutes makes it quick and easy for anyone to run the Android platform on their PC or Mac in no time at all.
owever, if you're just looking to install your favorite Android games on your PC and don't care about running a copy of the underlying operating system, your best bet is to read their tutorial for installing BlueStacks. BlueStacks allows you to simply download and run any Android game that is either currently existing on your Android device (using their Cloud Connect software), or that you can find and download on the Amazon or GetJar markets. It only takes a few minutes to install, and once it's running you can play virtually any Android game available on your PC