4. AUDIO
HTML5 Audio
+
Audio API
Saturday, February 2, 13
5. CANVAS
canvas = document.getElementById('canvas');
ctx = canvas.getContext('2d');
OR
<canvas id=game-canvas></canvas>
Saturday, February 2, 13
6. SPRITE
sprite = new Image();
sprite.src = /slideshow/build-your-own-game-with-html5/16307030/&
ctx.drawImage(sprite,srcX,srcY,frameWidth,frameHeight,frameX,frame
Y,renderWidth,renderHeight);
frame
Saturday, February 2, 13
7. ANIMATING SPRITE
sprite = new Image();
sprite.src = /slideshow/build-your-own-game-with-html5/16307030/&
function update(){
//check if object is moving
if(moving===true){
//move to next frame
srcX=srcX+frameWidth;
//reset frame when it reach last frame
if(srcX>srcWidth){
srcX=0;
}
}
}
function draw(){
ctx.drawImage(sprite,srcX,srcY,srcWidth,srcHeight,frameX,frameY,f
rameWidth,frameHeight);
}
Saturday, February 2, 13