Tuesday, September 9, 2014

Draw Call and FPS

         Performance is the crucial thing while you are dealing with game development for hand held devices! Before going optimized and performance oriented game development, one should understand key terms for measuring device performance. The major unit(yes we can say Unit) for device performance is FPS and Draw Call


FPS:

         FPS is Frame Per Second, time taken by device CPU to complete one frame. Human eye can see about 30 framers per second. So for smoother game play generally it is set to 60 for all Android, iOS and other mobile platforms so that graphics and all visuals are visible in high quality. So as a game developer one should try to achieve 60 FPS for game.


Draw Call:

         Draw Call is another unit that is concerned with device GPU(Graphics Processing Unit) directly. They are generated each time the CPU has to send data to the GPU for processing. Draw call can be stated as no of calls that GPU need to made to render an image/texture or mesh. The higher draw call the higher GPU call is made which results in higher power consumption. Higher draw call might also reduce FPS but this is not compulsory.

Saturday, August 30, 2014

Best Practice for Game Development

Hello developers,
           Here i am sharing game development phases that one should go with, Especially for indie game developers and studios.




           If you are planing to being game developer then their are lots of factors you should keep in mind, as being a game developer is not as easy as playing a game. It is inverse it.

Key phases for game development,


1. Market Research


           Before planning for any kind of game development one should make some research on current game trends, game user audience, game platforms etc. This would help a lot for your game and make you more clear what should you choose for your game.

         For example: If their is currently trend of 2048 kind of game then you can either go for same game development or similar kind of game development, so that you can easily redirect 2048 game users to you game and make money. Or if you are planning to rock the game market then you can choose your own concept and make it on stage. Its up to you how you are going!

Area of Research:

1. Current market trends
2. Targeted audience and country
3. Targeted platforms
4. Game category and scope
5. Age group

2. Game Design

           Game design is the main factor after market research if you are planning to develop a game, and it is ignored by most of indie game developer but i recommend to spend much time on designing a game rather planning for other stuffs. The more effort you made on designing the game the less effort would required on developing and marketing your game.

           For example : If you are planning to do like Subway Surfer like endless runner game then you will probably gathers basic requirements for your game and start development but in between of actual development if you will find more entertaining game then Subway Surfer then probably you would change your game design and this will result in delay of your product as well might be costly to packet.

Topics covered in game design:

1. Game story/Game concept
2. Game category
3. Game play and HUD design
4. Power ups
5. Future update
6. Dealing with developer team
7. Game engine selection and limitations
8. Multiple platform support
9. Marketing scenario

3. Graphics Development

           Once game design phase is completed the product would come in development phase, here it will come in graphics and UI development phase.


           If game is 3d then it would come in animation/model development and this would start your actual product development.

           Graphics development is very important part of your game as graphics is the one who makes first impression when you game is released. If game is containing eye catching graphics then use would probably download and play your game at least once.

4. Game Programming

           This is where your product is got rigged. Yes game programming is the phase where product is actually got rigged and lead to playable game.

           Game programming phase is one of most expensive phase of game development. Previous three phase would be gathered and programming team starts on product development. The more effort on programming makes product more engaging. This is where programming team is adding Physics, Animations, Event system, Third party tools, VFX(particles and all) and Sounds.

           Once game is downloaded journey is not stooped here, it is started actually. User would only sticked to game he/she found something engaging or unique in game otherwise he/she will simply uninstall game and never recommend others to play it. If he/she will found something engaging or unique in game they game would be played and also recommended to others. That would result in inter user marketing and of course that makes your pocket heavy.

5. Game Marketing(App Store Optimization)



           Once your product has been developed, tested and released successfully this phase starts. This is where your actual journey starts! Yes it is, your game is containing pretty and eye catching graphics, is has been executed nicely on game programming phase but if there is no marketing there is not installs of your game.

           This is where most of indie developer/studio got punched,  their are lost of game stores/portals are available, their are millions of games/apps on the game market, hundreds of game are released per day.. Out of them where your game would be ? Area of thinking.. Like any newly released website for game also their would require lots of marketing to attract user to download and play the game.


Marketing Agenda and Type

1. Social media marketing
2. Google AdMob or other advertiser platform 
3. Video marketing
4. Inter game or Inter user marketing
5.  Content based marketing

Tuesday, August 26, 2014

Getter and Setter in C# Unity3d

C# Unity has support for Getter and Setter properties which is very important in terms of Object Oriented Programming, Here is a simple example of Getter and Setter properties which shows its usefulness,
Without getter and setter properties:
  1. public int getX()
  2. {
    1. return x;
  3. }
  4. public void setX(int newX)
  5. {
  6. if(newX < 0)
  7. x = 0;
  8. else
  9. x = newX;
  10. }
To change the value of x you have to write like
  1. setX(getX()+4);
With getter and setter properties:
  1. public int X
  2. {
  3. get { return x; }
  4. set
  5. {
  6. if(value < 0)
  7. x = 0;
  8. else
  9. x = value;
  10. }
  11. }
Now in this case you can easily change value of x with 
  1. X += 4;
Getter and Setter is very usefull properties of C# programming language and can be utilize interestingly in Game Development also in Unity3d.

To know some basic but important key points about C# programming language go HERE,


Some basic use of these properties listed below,

1. Flexible way to get and set values conditionaly.
2. Works great with Unity3d Transform and other Vector properties.
3. Use mainly in Score/Health calculation/computaion etc.

Monday, July 28, 2014

Resolution Manager Script Unity3d

Hello developers,
As a mobile app/game developers it is not quite easy to make app/game UI same on different resolution devices,
In previous post you can see common resolutions with aspect ratios, also most used resolution devices among with that,
Below is the Unity3d Monobehaviour version of that discussion which is quite easy to get and use,

using UnityEngine;
using System.Collections;

public class ResolutionManager : MonoBehaviour 
{
public int bgWidthToLaod = 800;

float xWidth;
float yHeight;

void Awake()
{
xWidth = Screen.width;
yHeight = Screen.height;

float aspectRatio = xWidth / yHeight;

if(aspectRatio >= 1.30f && aspectRatio <= 1.35f)
{
// 2048 * 1536
aspectRatio = 1.33f;
bgWidthToLaod = 2048;
}
else if(aspectRatio >= 1.45f && aspectRatio <= 1.55f)
{
// 960 * 640
aspectRatio = 1.5f;
bgWidthToLaod = 960;
}
else if(aspectRatio >= 1.58f && aspectRatio <= 1.70f)
{
// 1280 * 768
aspectRatio = 1.67f;
bgWidthToLaod = 1280;
}
else if(aspectRatio >= 1.75f && aspectRatio <= 1.80f)
{
// 1136 * 640
aspectRatio = 1.78f;
bgWidthToLaod = 1136;
}
else
{
aspectRatio = 1.67f;
bgWidthToLaod = 1280;
}
}
}

Tuesday, July 22, 2014

Unity3d Important Methods and its Priority Order

Some Unity3d important methods and its usage with priority order,

[1] Awake : 

        Called just after object got initialized, also for prefab. It is called before Start function call. If gameobject is disabled Awake is not called, but if any function of this script or function of script attached to same object is invoked, object would be initialized and Awake is called. This is where most of developers got confused with Awake method invocation.
Priority : 1


[2] OnEnable : 

        This is called when Monobehaviour is enabled. It is also called before Start call. If object is not active this will not be invoked.
Priority : 2


[3] Start :

        Start is called before any frame update started if object is enabled.
Priority : 3

[4] FixedUndate :

        Fixed update is called more frequently then Update call if frame rate is low. If frame rate is high then it might called less frequently then Update call. Fixed update is called on reliable basis then Update function that's why you do not need to multiply movement calculation with Time.deltaTime. All physics related calculation should be placed inside FixedUpdate to make it behave correctly.
Priority : 4


[5] Update : 

        Update is called once per frame. This is main function in Unity3d Monobehaviour. If frame rate is set to be high then all input related code should be placed here to avoid input issues.
Priority : 5


[6] LateUpdate :

        LateUpdate is also called once per frame. The only difference between Update and LateUpdate is that its been called once Update has completed its execution. This will be very usefull in case where there is a need of task to be executed if and only if another task got completed. 
Example : Camera movement, score calculation, input management.
Priority : 6


[7] OnDisable : 

        This is called when Monobehaviour becomes inactive/disabled.
Priority : 7


[8] OnGUI :

        This function is called multiple time per frame, might call double then the Update call depending upon current frame rate. All input related code should be place in this function. Main use of this function is two draw various UI elements. Thought it is not advisable to use this function as of performance issues.

Sunday, July 20, 2014

Resoultions and Aspect Ratio

As a mobile game/app developer it is headache to port game/app to various mobile/hand held devices having different resolutions. Here is the list of resolutions for all major mobile and hand held devices which would help you while developing cross platforms mobile applications and games,

Resolutions* (AR*)

2048 * 1536 --> 1.33
1024 * 768 --> 1.33
1136 * 640 --> 1.78
960 * 640 --> 1.50
854 * 480 --> 1.78
800 * 480 --> 1.67
800 * 400 --> 1.50
2560 * 1536 --> 1.67
2560 * 1600 --> 1.60
1920 * 1080 --> 1.78
1920 * 1200 --> 1.60
1920 * 1152 --> 1.67
1824 * 1200 --> 1.52
1536 * 1152 --> 1.33
1280 * 720 --> 1.78
1280 * 800 --> 1.60
1280 * 768 --> 1.67
1024 * 600 --> 1.71
1024 * 800 --> 1.28
960 * 600 --> 1.60

* Resolutions are in Pixels
* AR - Aspect Ration

Most used aspect ratios,

1.33 - iPad, iPad 2, iPad Retina
1.50 - iPhone 4, iPhone 4s
1.67 - Most of Android devices
1.78 - iPhone 5, iPhone 5s, iPhone 5c, Android Tab Series

Monobehaviour script for resolutions and aspect ration is here.

Sunday, July 13, 2014

Facts About Unity3d Coroutines

         Here are some of important facts of Unity3d Coroutines which might help you,

1. You can only stop Coroutines that are invoked using StartCoroutine with string as a argument.


Example:


StartCoroutine("MethodName") can be stop using StopCoroutine("MethodName"),
Coroutines those are invoked as StartCoroutine(MethodName()) will not be cancelled by StopCoroutine("MethodName").

2. You can invoke other class Coroutine even after it is  marked as Private.

Example:


Class1.cs


using UnityEngine;
using System.Collections;

public class Class1 : MonoBehaviour {


// Use this for initialization

void Start () {
}

// Update is called once per frame
void Update () {
}

private void DemoCoroutine(){

print("Coroutine Invoked!");
}
}


Class2.cs


using UnityEngine;
using System.Collections;

public class Class2 : MonoBehaviour {


        // Reference Assigned in Inspector

public Class1 Class1Instance;

// Use this for initialization

void Start () {
        // You can even use singleton calss to invoke Coroutine defined in different class
Class1Instance.StartCoroutine("DemoCoroutine");
}

// Update is called once per frame
void Update () {
}
}


More about Unity3d Coroutine,

Friday, July 4, 2014

Shaders and It's Best Usage

Here is the basic details of Unity3d's inbuilt shaders and best usage of it,


Particles - Mobile/Particles/Alpha Blended
Particles - Mobile/Particles/Addictive
Transparent Background - Mobile/Particles/Alpha Blended
Line Renderer - Particles/VertexLit Blended

Tuesday, July 1, 2014

Facts about Resources folder in Unity3d

Some facts about Resource folder in Unity3d,

    The Resources folder is a special folder which allows you to access assets by file path and name in your scripts, rather than by referencing them in Unity Inspector.
  • All the assets of Resources will be included in build generated(even if it is not used in anyway).
  • Resources folder would not exist when build is generated, It exists in editor only.
  • Multiple resources folder can be used, Unity will examine assets from all the Resource folders. So it is not recommended to use same named asset in two different Resources folder.
  • All the assets found in Resources folder will be stored in resources.assets file, when build is generated.
  • It can be used to load Textures, Materials, AudioClips etc.
  • Prefab can also be instantiated directly form Resource folder as shown below,
Example,
GameObject gameObj = Instantiate(Resouces.Load("ObjectName", GameObject));
OR
GameObject gameObj = Instantiate(Resouces.Load<GameObject>("ObjectName"));
OR
GameObject gameObj = Instantiate(Resouces.Load("ObjectName", typeof(GameObject)));

Note : Only forward shash('/') is allowed to use to indicate path of assets in Resources, backward shash('\') would not work.


Sunday, June 29, 2014

Texture Fadein Fadeout using Coroutine - Unity3d

Code for making fadein, fadeout in Unity3d C#,


Fadein,

IEnumerator FadeIn(GameObject gameObj)
 {
  for (float f = 0f; f <= 1; f += 0.01f)
  {
   Color c = gameObj.renderer.material.color;
   c.a = f;
   gameObj.renderer.material.color = c;
   yield return new WaitForSeconds(.01f);
  }

  yield return null;
 }

Fadeout, 

IEnumerator FadeOut(GameObject gameObj)
 {
  for (float f = 1f; f >= 0; f -= 0.01f)
  {
   Color c = gameObj.renderer.material.color;
   c.a = f;
   gameObj.renderer.material.color = c;
   yield return new WaitForSeconds(.01f);
  }

  yield return null;
 }

Pre Requisites: Object you are passing  as argument must have shader which has color property in it.

FadeInFadeOut using NGUI UISprite and Coroutine,


 public UIAtlas RunTimeAtlas;

IEnumerator ColorFadeInFadeOut() 
{
UISprite newSprite = NGUITools.AddWidget<UISprite>(GameObject.Find("Story"));
newSprite.depth = 6;
newSprite.gameObject.name = "FadeInFadeOut";
newSprite.atlas = RunTimeAtlas;
newSprite.spriteName = "White120";
newSprite.SetDimensions (Screen.width * 3, Screen.height * 3);
TweenAlpha ta1 = newSprite.gameObject.AddComponent<TweenAlpha> ();
ta1.from = 0.0f;
ta1.to = 1.0f;
yield return new WaitForSeconds(1.10f);
TweenAlpha ta2 = newSprite.gameObject.AddComponent<TweenAlpha> ();
ta2.from = 1.0f;
ta2.to = 0.0f;
yield return new WaitForSeconds(1.0f);
NGUITools.Destroy(newSprite.gameObject);
}

Pre Requisites: Atlas reference must be assigned to RunTimeAtlas in Unity Inspector having white texture in it. Texture of other color can also be used for fade in and fade out effect.

Monday, June 23, 2014

Camera and Texture settings to make 2d game in Unity

Here are some basic Camera and Texture setting for 2d game development in Unity3d,


(1). Choose 'Point' as the filter mode for your textures.
(This is essential for making your textures sharp).

(2). Choose 'Advanced' as your 'Texture Type' and disable 'Generate Mip Maps'.
(This is also important for 2d game, it reduces texture size as well).

(3). Choose 'RGBA 32 bit' as your 'Texture Format'.
(Choose lesser until your texture quality remains, this is also for texture memory size).

(4). Set your Camera Projection to 'Orthographic'.
(To make game for 2d view only).

(5). Set your 'Orthographic Size' to your screen height / 2.
(This makes 1 unit in Unity equals 1 pixel on your textures).

(6). Create a Quad by following Menu -> GameObject -> Create Other -> Quad in Unity.

(7). Scale your Quad to same size as your texture.
(A 256*256 texture needs a 256*256 quad).

Note : Textures you are using must be POT(Power Of Two) textures.

Code snippets to set Camera size,


using UnityEngine;


public class 2dCameraScale: MonoBehaviour 
{
    void Awake () 
    {
        Camera.main.orthographicSize = Screen.height / 2;
    }
}

Post Note : The topic is posted for Unity3d v. 4.2.1 or older mainly, in newer versions their are lots of 2d related stuffs are added. Though you can use above settings for newer version also. ;)

Texture tiling with NPOT texture Unity3d

Thought NPOT(Non Power Of Two) textures are not advisable to use in Unity3d, but if you are using it then one important thing to note down here is that NPOT texture doesn't support Repeat Wrap Mode. If you are trying to used Repeat Wrap Mode with NPOT texture then it might result in improper tiling of a texture.

Wednesday, June 18, 2014

Show key/value pair in Unity3d Inspector

           By default Unity doesn't serialize Dictionary, So it is not possible to show key/value pair directly in Unity3d inspector. But this can be achieved using some simple tweaks shown below,

using UnityEngine;
using System.Collections;

[System.Serializable]
public class SoundManager : MonoBehaviour


public class AudioClip_Dir_Class
{
  public string audioClipName;
  public AudioClip audioClipvalue;
}

{
  public AudioClip_Dir_Class []audioClip_Dir;
}

Alternatively you can also go with below one,

public List<string> keys = new List<string>();
public List<MyClass> values = new List<MyClass>();
private Dictionary<string,MyClass> dict;

Tuesday, June 17, 2014

Texture compression and Optimization Unity3d

Always use Textures(for 3D only) in the power of Two(POT).
Because PVRTC only compress an image if it is in POT.
RGBA images are not compressed in iOS and they are saved without compressing. So it is preferable to use textures in the POT if it is texture of 3D model.

2D games shouldn't use compression at all, as the compression mess up with the alpha, which will cause semi transparent areas to look horrible.

To make 2D sprites, RGBA 32 Bit or 16 Bit texture is preferable for best graphics quality.

Games Must Have..

         Here three basic things Game Must Have to engage user and make impression in game market.


1. Nice concept

        This is where game development journey starts - A Good Concept. Game must have nice concept to stick user with game. One best example of this is very famous game Flappy Bird - A simple yet addictive game.


2. Eye catching graphics and User Interface(UI)

         As far as Game development concerns game must have nice, attractive graphics so that it would make very good impression on first see. Nice graphics are also very useful in marketing point of view. This is where simple rule works - "That which is seen is Sold".


3. Animations

        Yes it should be full of animations, Wait wait wait, let me make it clear this term.
        Here point of talk is, it should be full of Sprites(image sequences) for 2d games and animated/movable UI's for better user experience. Best example for this is Farm Heros Saga - A fun playing, entertaining game with full of animations.

        There are also other things like Particle Effects, Sounds etc. Which are also playing a role to make user experience better and too rock the game market.

Sunday, June 15, 2014

Factors affected and not affected by Time.timeScale

List of factors affected by Time.timeScale,


1. Coroutines
2. Invokes and InvokeRepeating
3. All physics related simulations (FixedUpdate())
4. Animations
5. Particle System

    To make it working, timeScale must be great than 0.0f. It would work even if it is set to 0.001f, Thought to run it on normal repeating rate, you should go for some short of simple logic,

For instance,
    If you want to work Animation even after timeScale is set to 0.001f, you should set animation speed to 0.001f / Time.timeScale. So it will go with regular frame rate.


List of factors doesn't affected by Time.timeScale,


1. Update()
    Time.timeScale will not make any affect on Update call, it will invoked as per the frame rate until and unless it is not used in any statement for computation.

For example,
float distance = Time.timeScale * 10.0f;
transform.Translate (0, 0, distance); 

will make affect on movement as Time.timeScale is being used while making object movement. It is moving object 10m/second.


while,
float distance = 10.0f;
transform.Translate (0, 0, distance); 

will not make any affect of timeScale on object movement and moving object  10m/frame instead.


2. OnGUI()
    OnGUI and its event have overlaying architecture over Time.timeScale, so it won't be affected if it goes to lower or set to 0.


Also see,

Saturday, June 14, 2014

Camera Shake J# Unity3d

var camera : Camera;
var shake : float = 0;
var shakeAmount : float = 0.7;
var decreaseFactor : float = 1.0;

function Update() 
{
  if (shake > 0) 
  {
    Camera.transform.localPosition = Random.insideUnitSphere * shakeAmount;
    shake -= Time.deltaTime * decreaseFactor;
  } 
  else 
  {
    shake = 0.0;
  }
}

Camera Shake C# Unity3d

using UnityEngine; using System.Collections; public class CameraShake : MonoBehaviour { public Transform camTransform; public float shake = 0f; public float shakeAmount = 0.7f; public float decreaseFactor = 1.0f; Vector3 originalPos; void Awake() { if (camTransform == null) { camTransform = GetComponent(typeof(Transform)) as Transform; } } void OnEnable() { originalPos = camTransform.localPosition; } void Update() { if (shake > 0) { camTransform.localPosition = originalPos + Random.insideUnitSphere * shakeAmount; shake -= Time.deltaTime * decreaseFactor; } else { shake = 0f; camTransform.localPosition = originalPos; } } }

Thursday, June 12, 2014

Time.timeScale and iTween ignoretimescale property

iTween property "ignoretimescale" doesn't work if it is used along with "delay" property withing same function.

For instance

iTween.MoveTo(gameObject,iTween.Hash("x", .25, "easetype", iTween.EaseType.easeInSine, "time", .2, "ignoretimescale", true, "delay", .2));

would be affected by Unity3d timeScale even though "ignoretimescale" property is used in it,

while,

iTween.MoveTo(gameObject,iTween.Hash("x", .25, "easetype", iTween.EaseType.easeInSine, "time", .2, "ignoretimescale", true));


will ignore Unity3d timeScale and "ignoretimescale" will function properly.

More important about Time.timeScale,

Best Practice for Game Development!

Popular Posts