September 27, 201510 yr So I was a tad inspired by Nillervision for trying to help his kid get into game programming and motivating him instead of mentioning the many pitfalls you can come across . So I got to work on a fairly simple Android game development framework which his kid can learn eventually or anyone else who may be interested in it once it's finished. That takes quite a lot of the hard work out of developing mobile games. Here is some examples a long with a screenshot of an example game. Create Game Object package com.rizodev.theandroidgameframework; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import com.rizodev.theandroidgameframework.interfaces.GameObj; /** * You can easily create a new game object * by implementing GameObj */ public class Player implements GameObj { //New Bitmap private Bitmap player; //X / Y private int x,y; public Player(Context context) { //Get player image player = BitmapFactory.decodeResource(context.getResources(), R.drawable.player); } @[member="OverRide"] public void update() { //Update code for the object goes here //Example code may be moving the object to the right //Object moves to right at a speed of 13 x+=13; } @[member="OverRide"] public Bitmap getBitmap() { return player; } @[member="OverRide"] public void setX(int x) { this.x = x; } @[member="OverRide"] public void setY(int y) { this.y = y; } @[member="OverRide"] public int getX() { return x; } @[member="OverRide"] public int getY() { return y; } } Creating a New View Below is a simple View using the Framework all you have to do is extend the Game class package com.rizodev.theandroidgameframework; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import com.rizodev.theandroidgameframework.core.Game; import com.rizodev.theandroidgameframework.core.Graphics; /** * Game Views consist of just 2 required methods and a constructor * The game loop and threads are automatically * created in the Game class all you have to worry about is * update() and render() * Created by steve on 9/25/15. */ public class MyView extends Game { public MyView(Context context) { super(context); } @[member="OverRide"] public void update() { //All updating takes place here } @[member="OverRide"] public void render(Canvas canvas) { //All drawing takes place here } } Lets Draw Something On Screen Using Our Game Object package com.rizodev.theandroidgameframework; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import com.rizodev.theandroidgameframework.core.Game; import com.rizodev.theandroidgameframework.core.Graphics; /** * Game Views consist of just 2 required methods and a constructor * The game loop and threads are automatically * created in the Game class all you have to worry about is * update() and render() * Created by steve on 9/25/15. */ public class MyView extends Game { //Reference our game object Player Player player; //Reference the frameworks graphics class Graphics g; public MyView(Context context) { super(context); //New instance of created Game Object player = new Player(); //Call static method getGraphicsManager g = Graphics.getGraphicsManager(); } @[member="OverRide"] public void update() { //Call objects update method player.update(); } @[member="OverRide"] public void render(Canvas canvas) { //Create new paint Paint p = new Paint(); //Clear last frame canvas.drawColor(Color.argb(255, 0, 0, 0)); //Draw the player on the canvas g.drawImage(player,player.getX(),player.getY(),canvas,p); } } to see the game framework in action here is an example android game built using the framework
September 27, 201510 yr Thanks for posting your work webdesigner93. What should use to compile the code. Android Studio?
September 27, 201510 yr Author Thanks for posting your work webdesigner93. What should use to compile the code. Android Studio? Yes it's all coded in android studio when i package up the basic framework in a day or so i'll send you it
Create an account or sign in to comment