12
BUILD YOUR OWN GAME WITH HTML5 Yohan Totting ThinkRooms Studio @tyohan Saturday, February 2, 13

Build your own game with html5

Embed Size (px)

DESCRIPTION

Basic knowledge about build a game using canvas. It's cover basic sprite animation and collision detection. Also include a game example.

Citation preview

Page 1: Build your own game with html5

BUILD YOUR OWN GAME WITH HTML5

Yohan TottingThinkRooms Studio

@tyohan

Saturday, February 2, 13

Page 2: Build your own game with html5

HALOYohan Totting

Application Developer Founder of ThinkRooms StudioFOWAB & HackerspaceBDG Initiator

Saturday, February 2, 13

Page 3: Build your own game with html5

HTML5 GAME COMPONENTS

Saturday, February 2, 13

Page 4: Build your own game with html5

AUDIO

HTML5 Audio

Audio API+

Saturday, February 2, 13

Page 5: Build your own game with html5

CANVAS

canvas = document.getElementById('canvas');ctx = canvas.getContext('2d');

<canvas id=”game-canvas”></canvas>

OR

Saturday, February 2, 13

Page 6: Build your own game with html5

SPRITEsprite = new Image();sprite.src = 'sprite.png';

ctx.drawImage(sprite,srcX,srcY,frameWidth,frameHeight,frameX,frameY,renderWidth,renderHeight);

frame

Saturday, February 2, 13

Page 7: Build your own game with html5

ANIMATING SPRITEsprite = new Image();sprite.src = 'sprite.png';

function update(){//check if object is movingif(moving===true){//move to next framesrcX=srcX+frameWidth;

//reset frame when it reach last frameif(srcX>srcWidth){

srcX=0;}

}}

function draw(){ctx.drawImage(sprite,srcX,srcY,srcWidth,srcHeight,frameX,frameY,frameWidth,frameHeight);}

Saturday, February 2, 13

Page 8: Build your own game with html5

BOXCOLLISIONDETECTION

BoxABoxB

if((BoxA.x + BoxA.width >= BoxB.x) && (BoxB.x + BoxB.width >= BoxA.x) &&((BoxA.y + BoxA.height >= BoxB.y) && (BoxB.y + BoxB.height >= BoxA.y)){  hit();}

Saturday, February 2, 13

Page 9: Build your own game with html5

FLOW

Setup()

Update()

Draw()

CheckCollation()

Animate()UpdateScore()

Saturday, February 2, 13

Page 10: Build your own game with html5

GAME ENGINE

LimeJS

Saturday, February 2, 13

Page 12: Build your own game with html5

CREATE YOUR OWN GAME!

Yohan TottingThinkRooms Studio

@[email protected]

Saturday, February 2, 13