Slide 1

Slide 1 text

Game Development Game Development with libgdx with libgdx Francis Lavoie @Flavoie http://slides.com/francisl/deck-1?token=em4fKUFS

Slide 2

Slide 2 text

A web A web developer's perspective developer's perspective

Slide 3

Slide 3 text

Where did it start Where did it start

Slide 4

Slide 4 text

The Commodore 64 The Commodore 64 source : http://en.wikipedia.org/wiki/File:Commodore_1541_front_cropped.jpg by Nathan Beach

Slide 5

Slide 5 text

Castle Siege and Conquest II Castle Siege and Conquest II

Slide 6

Slide 6 text

Ascendancy Ascendancy

Slide 7

Slide 7 text

Then I realized that I wanted Then I realized that I wanted to be a game developer to be a game developer

Slide 8

Slide 8 text

A unique place to unleash A unique place to unleash your creativity your creativity

Slide 9

Slide 9 text

Past experiments Past experiments

Slide 10

Slide 10 text

Search of fire Search of fire Focus on the fun part first No clear plan

Slide 11

Slide 11 text

Spacebug Spacebug crusher crusher Make a game you want to play

Slide 12

Slide 12 text

zonfbie zonfbie Hard to have commitment from the entire team Team organisation

Slide 13

Slide 13 text

Technology Technology

Slide 14

Slide 14 text

Why I chose libgdx Why I chose libgdx Multi OS targets Web target Multi OS development Active community Bunch of modules

Slide 15

Slide 15 text

Other possible Other possible candidates candidates

Slide 16

Slide 16 text

2d 2d JavaScript webgl fallback to canvas (pixi.js) JavaScript webgl Phaser EaselJS

Slide 17

Slide 17 text

3d 3d C#, boo, unityscript Native Desktop, Mobile and webgl JavaScript webgl JavaScript, TypeScript webgl JavaScript webgl unity3d.com threejs.org babylonjs.com biz.turbulenz.com

Slide 18

Slide 18 text

If you want more If you want more choices choices http://html5gameengine.com http://html5gameengine.com http://forums.tigsource.com/index.php?topic=21471.0 http://forums.tigsource.com/index.php?topic=21471.0

Slide 19

Slide 19 text

Strategies learned Strategies learned

Slide 20

Slide 20 text

The pen is the ideal tool for The pen is the ideal tool for prototyping prototyping Levels A rough back-story with base character Items, power-ups or any other elements Design sketch

Slide 21

Slide 21 text

Core Game Mechanics Core Game Mechanics Object/Enemies' interactions How to die Navigation Points? Perks? Bonus Physics

Slide 22

Slide 22 text

Key qualities Key qualities 1. Are entered willfully 2. Have goals 3. Have conflict 4. Have rules 5. Can be won and lost 6. Are interactive 7. Have a challenge 8. Can create their own internal value 9. Engage the player 10. Are a closed, formal system Games Games ** from The Art of Game Design by Jesse Schell

Slide 23

Slide 23 text

Start ugly but Start ugly but playable playable

Slide 24

Slide 24 text

A web A web developer's perspective developer's perspective

Slide 25

Slide 25 text

Expectations Expectations 6 months is enough Programming is the most important part of the job!

Slide 26

Slide 26 text

Challenge for a web developer Challenge for a web developer No more request-based call No routes and controller No more business logic - but real math No more transparent GC in the background

Slide 27

Slide 27 text

Plus a bunch of new tools Plus a bunch of new tools A java IDE (Intellij/Eclipse) Or any other authoring tools Graphic editor Texture (map, atlasing) Sound editing

Slide 28

Slide 28 text

Basics Basics

Slide 29

Slide 29 text

Game blocks Game blocks Application main game Screen Game loop Events Actors UI, Fonts TileMaps Animations Sounds & music

Slide 30

Slide 30 text

Main game Main game import com.badlogic.gdx.Game; public class AlbatrosD2Game extends Game { public String title = "Albatros DII"; public MenuScreen getMenuScreen() { return new MenuScreen(this); } public PlayScreen getPlayScreen() { return new PlayScreen(this); } @Override public void create () { setScreen(getPlayScreen()); } @Override public void render () { super.render(); } }

Slide 31

Slide 31 text

Actors Actors ... public class Bullet extends GameActor { public Bullet(int speed, float scale, float angle Vector2 pos, Vector2 direction, ){ } @Override public void draw(Batch batch, float alpha){} }

Slide 32

Slide 32 text

Make it less ugly Make it less ugly

Slide 33

Slide 33 text

What you will need What you will need Graphics Tile Spritesheet UI Widgets Fonts

Slide 34

Slide 34 text

Tools Tools Krita/gimp Texture packer Tiled

Slide 35

Slide 35 text

TexturePacker TexturePacker Create sprite/spritesheet Color optimization Trimming Cropping

Slide 36

Slide 36 text

TexturePacker TexturePacker

Slide 37

Slide 37 text

Free Free opengameart.org Free + $ Free + $ www.graphic-buffet.com $ + $$ $ + $$ graphicriver.net/category/game-assets

Slide 38

Slide 38 text

Put some life in Put some life in actors actors

Slide 39

Slide 39 text

Take Take control control import com.badlogic.gdx.Input; @Override public void act(float delta){ if(Gdx.input.isKeyPressed(Input.Keys.A)) { movingSideway = moveLeft(); } else if(Gdx.input.isKeyPressed(Input.Keys.D)) { movingSideway = moveRight(); } }

Slide 40

Slide 40 text

Remember trigonometry? Remember trigonometry? Target an enemy Calculate direction Get the distance between two objects http://www.raywenderlich.com/35866/trigonometry-for-game-programming-part-1 by Matthijs Hollemans

Slide 41

Slide 41 text

Radians vs. Radians vs. degress degress Radians are expressed in terms of π 1 radian = radius length on the arc of the circle ~6.28 radian = Circle arc 2π radian = Circle arc = 360 degrees Angle in degrees = (Angle in radians / 2π) * 360

Slide 42

Slide 42 text

atan2 atan2 atan2() angle between the hypotenuse and the 0-degree line atan2f() returns a value in radians

Slide 43

Slide 43 text

Know angle Know angle and length and length Know 2 sides Know 2 sides sin(angle) = opposite / hypotenuse cos(angle) = adjacent / hypotenuse tan(angle) = opposite / adjacent angle = arcsin(opposite / hypotenuse) angle = arccos(adjacent / hypotenuse) angle = arctan(opposite / adjacent)

Slide 44

Slide 44 text

Pythagoras theorem Pythagoras theorem opposite2 + adjacent2 = hypotenuse2 opposite2 + adjacent2 = hypotenuse2

Slide 45

Slide 45 text

Set the direction of an actor private Vector2 direction = new Vector2(); float angleRadians = (rotationAngle+90) * MathUtils.degreesToRadians; direction.set(MathUtils.cos(angleRadians), MathUtils.sin(angleRadians)).nor(); Compute the trajectory private Vector2 direction; private Vector2 position = new Vector2(); private Vector2 computeVelocity = new Vector2(); computeVelocity.set(direction).scl(velocity); position.add(computeVelocity); sprite.setX(position.x); sprite.setY(position.y);

Slide 46

Slide 46 text

Nothing's flying Nothing's flying

Slide 47

Slide 47 text

Tiledmap Tiledmap Parallax Parallax

Slide 48

Slide 48 text

Orthogonal Orthogonal

Slide 49

Slide 49 text

Isometric Isometric Staggered Staggered

Slide 50

Slide 50 text

import ...OrthogonalTiledMapRenderer; public class ParallaxBackground { public ParallaxBackground (float w, float h, String mapSelection){ map = new TmxMapLoader().load("tiles/daland.tmx"); mapRenderer = new OrthogonalTiledMapRenderer(map); camera = new OrthographicCamera(); camera.viewportHeight = h; camera.viewportWidth = w; camera.position.y = h/2; MapProperties prop = map.getProperties(); int mapWidth = prop.get("width", Integer.class); int mapHeight = prop.get("height", Integer.class); int tilePixelWidth = prop.get("tilewidth", Integer.class); int tilePixelHeight = prop.get("tileheight", Integer.class); mapPixelHeight = mapHeight * tilePixelHeight; } public void render(float velocity){ if (camera.position.y > mapPixelHeight + camera.viewportHeight){ cameraElevation = 0 - (int) camera.viewportHeight; } camera.translate(0, 1f * velocity, 0); camera.update(); mapRenderer.setView(camera); mapRenderer.render(); } }

Slide 51

Slide 51 text

Performance Performance

Slide 52

Slide 52 text

Object pool Object pool The garbage collector is your enemy public abstract class GameActorPool { public ArrayList actorArray; public ArrayList deadActorArray; public List tmpGameActorList; protected Group group; public GameActorPool(Group group){ this.group = group; actorArray = new ArrayList(); deadActorArray = new ArrayList(); tmpGameActorList = new ArrayList(); } ... public boolean hasActor(){ return actorArray.size() > 0; } public void reset(){ ... int dasize = deadActorArray.size(); for(int i = 0; i < dasize; i++){ GameActor b = deadActorArray.get(i); b.reset(); actorArray.add(b); } deadActorArray.clear(); } }

Slide 53

Slide 53 text

Example html canvas Example html canvas

Slide 54

Slide 54 text

Many objects need to Many objects need to be manually deallocated be manually deallocated https://github.com/libgdx/li https://github.com/libgdx/li bgdx/wiki/Memory- bgdx/wiki/Memory- management management

Slide 55

Slide 55 text

Collisions Collisions

Slide 56

Slide 56 text

Use of actor rectangle Use of actor rectangle Fast Simple Work with html target

Slide 57

Slide 57 text

Simple Simple collision collision public Boolean collidingWith(GameActor actor){ if (actor.state == State.ALIVE && this.state == State.ALIVE && Intersector.overlaps(this.getRectangle(), actor.getRectangle())) { this.collide(); actor.collide(); return true; } return false; }

Slide 58

Slide 58 text

Animation Animation

Slide 59

Slide 59 text

Tools Tools TexturePacker Spine

Slide 60

Slide 60 text

// EXPLOSION protected static final int FRAME_COLS = 4; protected static final int FRAME_ROWS = 4; protected static final String EXPLOTION_SPRITE = "sprites/explosion/explosion1.png"; public void createExplosion() { explosionSheet = new Texture(Gdx.files.internal(EXPLOTION_SPRITE)); TextureRegion[][] tmp = TextureRegion.split(explosionSheet, explosionSheet.getWidth()/FRAME_COLS, explosionSheet.getHeight()/FRAME_ROWS); TextureRegion[] explosionFrames = new TextureRegion[FRAME_COLS * FRAME_ROWS]; int index = 0; for (int i = 0; i < FRAME_ROWS; i++) { for (int j = 0; j < FRAME_COLS; j++) { explosionFrames[index++] = tmp[i][j]; } } explosionAnimation = new Animation(0.055f, explosionFrames); } public boolean drawExplosion(Batch batch, float posX, float posY, float width, float height) { explosionTime += Gdx.graphics.getDeltaTime(); explosionCurrentFrame = explosionAnimation.getKeyFrame(explosionTime, true); batch.draw(explosionCurrentFrame, posX, posY, width, height); return (explosionTime > 0.45f); }

Slide 61

Slide 61 text

Ambiance Ambiance

Slide 62

Slide 62 text

Sounds & music Sounds & music dig.ccmixter.org freesound.org bfxr.net Creative Common music Collection of soundfx Free sound mixer

Slide 63

Slide 63 text

Mobile & Html Mobile & Html

Slide 64

Slide 64 text

Technologies Technologies RoboVM [GWT]

Slide 65

Slide 65 text

Fin Fin http://francisl.net/2015/02/18/game-development-links/ https://joind.in/13344