Android Game Development

Introduction

Android Game Development can be achieved by using Unity Game Engine.

Unity is a cross-platform game creation engine developed by Unity Technologies. Unity, first of all is easy to use, and it is a cross platform game development engine, so one can create desktop games, android games, ios games, etc.

Our Aim here will not be making a game completely, but getting the basic idea of using Unity, and then you can continue on your own.

For Android Game Development, You Should have the Android SDK

Getting Started

Using Unity, mobile game development is no different than making a desktop game. The only thing which needs careful attention is about the input. In desktop we have a whole keyboard, but on a mobile device, we just have a touch screen. So basically input makes Android Game Development a bit different.

So basically we can start with making a desktop game (keeping in mind the input factor), and then in the end, take care of the input

And for simplicity or as a beginner one should begin with 2-D game development. And that is what we'll do.

Getting to know the Basics of Game Development

1. Sprite Sheets

A sprite sheet is an image, with is a collection of small images. The image represents a character's movement, and the small images in it, are the images of the character at different frames, which if seen very fast one after the another, looks like the character is in motion.

runningGrant.png

2. Animation

Unity gives many options on how one can manipulate a character's movement. Animations are achieved by using sprite sheets.

3. Scripts

Unity has support for scripting languages such as C#, JavaScript and Boo. It is not the same java script used on web. or C# that we use. They are scripting languages of Unity.
So basically a script is used for implementing a logic on a game object. Like movement of any game-object, or say jumping, colliding, etc.

Implementing In Unity (BASICS)

First of all I'll be showing you how can you move an object. We'll be moving a static image, that is something with no ongoing animations.

1. Open Unity. On opening it will ask the path where you want to start your project, and if you just lower your eyes, you'll find an option whether to work in a 2-D or 3-D environment.

1.JPG

2. Drag and drop and image or any character. Well, I'll be using a ground and a character, so as to provide more learning experience. (My ground is a box, made in paint, so you can also make one, and character is from web)
2.png

  • Then Select your character, go towards right, and select Add Component then Physics 2D then Box Collider.
  • Then again with character selected, Add Component then Physics 2D then Rigidbody2D.
  • By doing this, we have made our image follow the laws of physics. Rigidbody2D gives it mass, follow gravity and box collider will make it capable of detecting collisions. See the image, I've added the components.
3.png
  • Now if you run your game, you'll see your character falls down, not even stopping colliding with your ground.
  • So to solve this, and make our ground working we can just simply add a Box Collider to it.
  • Once done that, if you hit play, you can see that your character stands on the ground.
4.JPG
  • Now lets add some Script, to make our player capable of moving left and right.
  • So go ahead, Add Component then New Script and we'll be using JAVASCRIPT, cause that's easy to grasp.
  • Once done that, double click and it should open up in Mono Develop.
  • And now we can start writing our script.

//Script
#pragma strict

var left : KeyCode; // variable which can be assigned any key from keyboard
var right : KeyCode; // variable which can be assigned any key from keyboard
var up : KeyCode; // variable which can be assigned any key from keyboard

var speed : float = 10; variable that stores a float with value 10//

function Update () Update function, which like updates the game after every second.
{
if( Input.GetKey(left)) //
Checks if the key assigned to left is pressed or not
{
rigidbody2D.velocity.x = speed*-1; //
Since we have added rigidbody2d, and velocity is an inbuilt function, and movement will be on x-axis, this line of code will make x-velocity to -10, making it move to left
direction, if key is pressed.

}
else if(Input.GetKey(right)) Checks if the key assigned to right is pressed or not
{
rigidbody2D.velocity.x = speed; //
Since we have added rigidbody2d, and velocity is an inbuilt function, and movement will be on x-axis, this line of code will make x-velocity to 10, if key is pressed.
}
else if(Input.GetKey(up)) //
Checks if the key assigned to left is pressed or not
{
rigidbody2D.velocity.y = speed; //
This line of code is used for a jump
}
else
{
rigidbody2D.velocity.x = 0; //
If nothing is pressed, we would like our player to be stationary//
}

}

  • And now once our script is ready, we need to assign keys to our variable.
  • So, first we'll select our character, then go to the right where we'll be able to see our script and there we'll see our variable names, assigned to nothing.
  • So we can assign them keys.
5.JPG

Making game Mobile Camptible

Now to export the above game(if we can call it one) to a touch screen mobile device, I'll be using Android here, we need to worry about the input. We don't have left or right arrow keys on mobile.

So now there are a many ways of doing it, like we can either make the character move when we specifically tap at a part of the screen or we can make the character move while our finger is also moving.

We'll be looking how can we move a character while our finger also moves.

  • Now to begin, we will make a new C# script to handle touch. JavaScript script can be used for desktop and we can use C# script for managing touch.
  • It is our to our preference, we can use JavaScript for both touch and keyboard. Well, I think C# would do great, so thus using C#. You can use any Script.
  • Now create a new script, un-check the previous JavaScript.
  • Write the following code :

using UnityEngine;
using System.Collections;

public class TouchCharMove : MonoBehaviour {

// Update is called once per frame
void Update () {
//tells us how many finger have we touched to the screen, works only if one finger is touched.
if(Input.touchCount == 1)
{
//well now our phones can handle multi-touches so touches are stored in an array. So variable xx, using a built in function deltaPosition which tells how much the input(finger) has moved.
float xx = Input.touches[0].deltaPosition.x * .03f; //this multiplication is done to slower down the movement, try removing and then running it

//and in accordance to the distance calculated the transform.Translate moves our object that much distance.
transform.Translate(xx,yy,0);
}
}
}

  • And we are done with the touch Script too.
  • Now we are just left with testing our game.

Exporting The Game

  • Go to Edit.
  • Then to Preferences
  • External Tools, and locate you Android SDK path.
7.JPG
  • Then go to File.
  • Build Settings.
  • Select Android, and from below, Switch Platform.
9.JPG
  • Next click on player setting given below, and to from the right click on Other Settings and from there change the name of Bundle Identifier.
8.JPG
  • And under Resolution And Presentation select landscape left from Default Orientation.
  • Once done that, connect your phone to you pc/laptop.
  • Before connecting remember to turn on USB Debugging on your phone otherwise it won't work.
  • And then finally click on build and run.
  • Unity will do its compiling and other stuff, and will generate an apk file, install it for you to your device and it will open up completely working (If done Properly).

Thank You For Your Patience Reading.

Made By

Darvesh Punia - 2014034
Ashutosh Nandan - 2014024
Vasu IIITD - 2014114

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License