Android 2D Game Tutorial for Beginners
This document is based on:
Android Studio 1.5
Target of the document is help you to become acquainted with a few simple techniques in programming Android Game 2D. Include:
- Use SuffaceView
- Drawing on a Canvas
- The motion of the game character.
- Interactions with the player's gestures
In this document, I will guide you step by step, therefore, you need to read and practice up to down. We will write each version of the game from 1 to the final version.
2- Create a Game Project
Note that you're creating a 2D game on Android, so the interface of the game must be drawn by you, so you do not need aactivity_main.xml file.
OK, your Project was created.
3- Preparing Images and sounds
You need a few images
- chibi1.png
- chibi2.png
- explosion.png
The Audio file of the explosion.
Background sound:
Copy these images to the drawable folder of project. Create raw folder, and copy explosion.wav & background.mp3 to this folder.
4- Setting fullscreen (Version:1)
With games, you need to set the background image and an important thing is that you need to set FullScreen mode.
Your MainActivity class must extends from the Activity class .
MainActivity.java (Version: 1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| package org.o7planning.androidgame2d; import android.app.Activity; import android.os.Bundle; import android.view.Window; import android.view.WindowManager; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); // Set fullscreen this .getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // Set No Title this .requestWindowFeature(Window.FEATURE_NO_TITLE); } } |
Running apps:
沒有留言:
張貼留言