tools for developing android games

54
Tools for Android Games Raul Portales @sla_shalafi [email protected] @thepilltree http://thepilltree.com

Upload: platty-soft

Post on 13-Jan-2015

6.591 views

Category:

Technology


6 download

DESCRIPTION

Slides from the workshop: Tools for developing Android Games, held on March 24th, 2012 at Amsterdam.

TRANSCRIPT

Page 1: Tools for developing Android Games

Tools for Android Games

Raul Portales@[email protected]

@thepilltreehttp://thepilltree.com

Page 2: Tools for developing Android Games

Summary

● Introduction to game development● Engines

● AndEngine● jPCT-AE

● Scores / Achievements● Monetization systems

Page 3: Tools for developing Android Games

Game Architecture (Simplified)

Game Engine

Game Objects Update ThreadDraw Thread

Page 4: Tools for developing Android Games

Performance Tips

● Avoid object creations● Use pools and pre create them

● Avoid getters and setters● Public attributes instead

● Avoid collections● Avoid interfaces● Use a single Activity

Page 5: Tools for developing Android Games

Why use OpenGL?

Performance

Page 6: Tools for developing Android Games

Why use OpenGL?

Performance

Page 7: Tools for developing Android Games

Why use any Engine

You don’t want to start from scratch

Page 8: Tools for developing Android Games

AndEngine

Page 9: Tools for developing Android Games

AndEngine

● http://www.andengine.org/● 2D Graphics Engine● LGPL● Extensions

● Physics Engine (Box2D)● Live Wallpapers● etc

Page 10: Tools for developing Android Games

Games built with AndEngine

● Chalk Ball● Bunny Shooter● Greedy Spiders● Wheelz● Farm Tower● ...

Page 11: Tools for developing Android Games

Games built with AndEngine

Page 12: Tools for developing Android Games

Project setup

● Put the jar under libs● Add them to the build

path

● Don’t forget “armeabi”● Get the source

● Import project● Create res dir

Page 13: Tools for developing Android Games

Concepts

● Engine● Scene

● Sprites + Handlers

● Texture / Texture Atlas● Sprite● Body

● Fixture

Page 14: Tools for developing Android Games

Game Architecture / AndEngine

Game Engine

Game Objects Update ThreadDraw Thread

Scene UpdateHandler

Sprites

Page 15: Tools for developing Android Games

Activity creation flow

● BaseGameActivity● onLoadEngine● onLoadResources● onLoadScene● onLoadComplete

Page 16: Tools for developing Android Games

Creating the Engine (1/2)

public Engine onLoadEngine() {

DisplayMetrics om = new DisplayMetrics();

getWindowManager().getDefaultDisplay().getMetrics(om);

camWidth = 480;

camHeight = (int) (om.heightPixels*480f / om.widthPixels);

RatioResolutionPolicy rrp = new RatioResolutionPolicy(camWidth, camHeight);

Camera camera = new Camera(0, 0, camWidth, camHeight);

Page 17: Tools for developing Android Games

Creating the Engine (2/2)

EngineOptions options = new EngineOptions(true, ScreenOrientation.LANDSCAPE, rrp, camera);

options.getRenderOptions()

.disableExtensionVertexBufferObjects();

return new Engine(options);

}

Page 18: Tools for developing Android Games

Loading Resources

public void onLoadResources() {

BitmapTextureAtlas bitmapTextureAtlas = new BitmapTextureAtlas(64, 64, TextureOptions.BILINEAR_PREMULTIPLYALPHA);

mBoxTextureRegion = BitmapTextureAtlasTextureRegionFactory .createFromAsset(bitmapTextureAtlas, this, "box_icon.png", 0, 0);

mEngine.getTextureManager() .loadTexture(bitmapTextureAtlas);

}

Page 19: Tools for developing Android Games

Texture Atlas

● Quite a pain for AndEngine● Built by hand● Size must be a power of 2● One big or many small ones?

Page 20: Tools for developing Android Games

Creating the Scene (1/3)

public Scene onLoadScene() {

Scene scene = new Scene();

PhysicsWorld physicsWorld = new PhysicsWorld(new Vector2(0, SensorManager.GRAVITY_EARTH), false);

Shape ground = new Rectangle(0, camHeight - 2, camWidth, 2);

FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0, 0.5f, 0.5f);

PhysicsFactory.createBoxBody(physicsWorld, ground, BodyType.StaticBody, wallFixtureDef);

scene.attachChild(ground);

Page 21: Tools for developing Android Games

Creating the Scene (2/3)

Sprite box = new Sprite(0, 0, mBoxTextureRegion);

FixtureDef boxFixture = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f);

Body boxBody = PhysicsFactory.createBoxBody(physicsWorld, box, BodyType.DynamicBody, boxFixture);

physicsWorld.registerPhysicsConnector(new PhysicsConnector(box, boxBody, true, true));

scene.attachChild(box);

Page 22: Tools for developing Android Games

Creating the Scene (3/3)

scene.registerUpdateHandler(physicsWorld);

scene.registerUpdateHandler(mUpdateHandler);

return scene;

}

Page 23: Tools for developing Android Games

Types of bodies

● Dynamic● It is affected by physics like gravity

● Kinematic● It moves in a specified way

● Static● It does not move

Page 24: Tools for developing Android Games

More Interesting things

● TiledTextures / Animated Sprites● Animations● Sound Engine● Particle Systems● Collision Detect● Polygonal Bodies● Menus

Page 25: Tools for developing Android Games

Intermission

← AndEngine Example apk

Page 26: Tools for developing Android Games

jPCT-AE

Page 27: Tools for developing Android Games

jPCT-AE

● http://www.jpct.net/jpct-ae/● 3D Engine

● 3DObjects● Lights● etc

● No physics● It has collision detection

Page 28: Tools for developing Android Games

Games built with jPCT-AE

● SpaceCat● SkyFrontier● Forgotten Elements● Mobialia Chess● Freddy Budgett● Alien Runner● ...

Page 29: Tools for developing Android Games

Games built with jPCT-AE

Page 30: Tools for developing Android Games

Project setup

Add jpct-ae.jar to libs / Build path

Page 31: Tools for developing Android Games

Concepts / Classes

● Renderer / FrameBuffer● World● Texture / TextureManager● Object3D● Light● Camera

Page 32: Tools for developing Android Games

Game Architecture / jPCT-AE

Game Engine

Game Objects Update ThreadDraw Thread

Renderer World

3DObject

Page 33: Tools for developing Android Games

Preparing the GLSurfaceView

mGlView = (GLSurfaceView) findViewById(R.id.glview);

mGlView.setKeepScreenOn(true);

mViewRenderer = new MyRenderer(mGlView, mWorld);

mGlView.setRenderer(mViewRenderer);

Page 34: Tools for developing Android Games

Renderer setup

public void onDrawFrame(GL10 gl) {

buffer.clear(back);

synchronized (mWorld) {

mWorld.renderScene(buffer);

mWorld.draw(buffer);

}

buffer.display();

}

Page 35: Tools for developing Android Games

Setup the World

mWorld = new World();

mWorld.setAmbientLight(150, 150, 150);

Page 36: Tools for developing Android Games

Loading Textures

Resources res = getResources();

Texture texture =

new Texture(res.getDrawable(R.raw.texture));

TextureManager.getInstance()

.addTexture("texture", texture);

Page 37: Tools for developing Android Games

Loading Objects

mModel = Loader.load3DS(getResources()

.openRawResource(R.raw.model), 1)[0];

mModel.setTexture("texture");

mWorld.addObject(mModel);

mWorld.buildAllObjects();

Page 38: Tools for developing Android Games

Creating Lights

Light sun = new Light(mWorld);

sun.setIntensity(250, 250, 250);

SimpleVector sv = new SimpleVector(0, -100, -100);

sun.setPosition(sv);

Page 39: Tools for developing Android Games

Handling the camera

Camera cam = mWorld.getCamera();

cam.setPosition(new SimpleVector(0, 0,-100));

cam.lookAt(mModel.getTransformedCenter());

Page 40: Tools for developing Android Games

More about the camera

● It has a position● Camera.setPosition

● It has a target● Camera.lookAt

● It has a rotation● Camera.setRotation

Page 41: Tools for developing Android Games

The 3D axis

Page 42: Tools for developing Android Games

Operations with objects

● Hierarchy● addChild

● Move● setPosition / translate

● Rotation● rotateX, rotateY, rotateZ

Page 43: Tools for developing Android Games

More Interesting Things

● Keyframe Animations● Collision detect (Ellipsoids)● Billboards● Transparency● Culling● Primitive Objects

Page 44: Tools for developing Android Games

And a workaround

● Overlay native layouts● Menus● Dialogs

Page 45: Tools for developing Android Games

Another Intermission

← jPCT-AE Example apk

Page 46: Tools for developing Android Games

Bonus: Other Engines● PlayN

● https://developers.google.com/playn/

● NME ● http://www.haxenme.org/

● Unity ● http://unity3d.com/

● Game Maker ● http://www.yoyogames.com/make

Page 47: Tools for developing Android Games

Scores / Achievements

Page 48: Tools for developing Android Games

Why use a Library?

● Not reinventing the wheel● It is proven that works

● Familiarity for users● Other games use them

● You do not own the servers● You don’t, and that is good

Page 49: Tools for developing Android Games

Available libraries

● ScoreLoop ● OpenFeint

Page 50: Tools for developing Android Games

What do you get?

● Achievements● Not very impressive

● Leaderboards● That is interesting

● News Feed● Friends management● Improved engagement

Page 51: Tools for developing Android Games

Easy to integrate

● Android Library Project● Initialize with the Application● Open a specific screen

● 2 lines of code

● Submit a score or achievement● 2 lines of code

Page 52: Tools for developing Android Games

Monetization

Too much to say for a single slide

Page 53: Tools for developing Android Games

And now...

● Lunch● Pitch your game idea

● Gather a team

● Hackaton● Demos, Pizza & Beer

Page 54: Tools for developing Android Games

Tools for Android Games

Raul Portales@[email protected]

@thepilltreehttp://thepilltree.com