Android Game Development Tutorial – Surface View

Welcome friends, to our Android Game Development Tutorial Series. In this android game development tutorial series we will be creating a complete game. This is the first part of the series and today we will start creating our game. So lets begin.

Pre requisites to start Android Game Development Tutorial

  • Android Studio (But you can also use eclipse with sdk)

Video Tutorial

  • You can also check out the video of this android game development tutorial of you don’t like reading 😛

Now lets begin creating our game

  • Open Android Studio -> New Project.
  • Fill your application name and company domain.
  • Select a blank activity.
  • Hit finish.
  • Right click on your package -> New -> Java Class.
  • Now create a new java class for your Game’s main screen I named it GamePlay.
  • Paste the both images you have downloaded to the drawable folder of your project.
  • Now come to your class and write or copy the following code.

  • As you can see the above class is extending SurfaceView. SurfaceView provides a surface to draw things on it. You can read the more about android surface view.
  • Then we declared a Bitmap object for our character.
  • And we are using a SurfaceHolder to track our surface.
  • We added a callback to our surface which gives us three methods. For now we will be working on surfaceCreated() method.
  • Inside surfaceCreated() method we are creating a Canvas object. We locked the canvas while we are drawing on the canvas because when we are drawing on the canvas we don’t want other threads to access it.
  • Finally we are using the onDraw method to draw our character to the screen by passing the canvas object.

Finalizing this part of Android Game Development Tutorial

  • Now you need to set content of your MainActivity as your GamePlay class. You can do it simply with the following code.

  • Here we are removing the title of our app, because we want our app to run in full screen.
  • Now finally in setContentView method we will pass our GamePlay class.
  • Execute your project and Bingo! it works.
  • Leave your comments if you are having troubles following the steps. You can also download the source code from the link given below.

Download Source

So thats it for this part friends. In the next part of our Android Game Development Tutorial we will start creating our character and will do some more interesting stuffs.

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!


      • innocentboy says

        ic_launcher are not in a android studio library function if i write ic_launcher there is a error in a program please help

  1. Tech Torpedo Blog says

    This is handy, i’m just moving from android development with gamesalad to programming with android stuido, and obviosuly the surface is the starting point. Need to get this right, thanks for the resources.

  2. pulkit says

    Can you make a zip file of the images you used in second part of this tutorial and give me a Google drive link by uploading it to your drive and give me the share link of the zip.

    Please help me in this
    I am stuck at the second part of the tutorial.

    You can also send the zip to my gmail id if you find it easier.

    Thanks in advance.

  3. Vishal Gupta says

    hi belal, can u please upload tutorials 4 and more for the android game development???
    please reply

  4. Vasim says

    I am new in this field.But If you have idea of how to open an account with play store.Please upload this kind of stuff or mail me details.

  5. Komal says

    I really like your blog n i thought it’s beneficial to me.
    Will you please send me the link of All the parts of Android Game Application Tutorial?
    I want to make puzzle game, for that i need your help to create next level of game. Please help me out.

  6. says

    Hi, i was tried in Eclipse fully loaded with AndEngine. i did as you shown in the video and there is no error shown. but the emulator giving a error that force to stop. plz tell me where i am going to wrong. by answer here. plz plz plz

    • says

      Use R.mipmap.icon or you can copy any image inside the drawable folder.. as updated android studio is changed a little that is why it is causing error.

Leave a Reply

Your email address will not be published. Required fields are marked *