The Essential Guide to HTML5

(Greg DeLong) #1

CANNONBALL AND SL INGSHOT


Code Explanation


ctx.drawImage(this.img,this.sx,this.
sy,this.swidth,this.sheight);


}


var target = new Picture(700,210,209,
179,chicken);


Build new Picture object and assign it to
target

var ground = new myrectangle(0,370,
1200,30,"rgb(10,250,0)");


everything.push(target);


everything.push(ground); Put the ground on top of the chickens feet


everything.push(mysling);


everything.push(cball);


function init(){


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


canvas1 = document.getElementById
('canvas');


canvas1.addEventListener('mousedown',
findball,false);


Set up event handling for the mousedown event

canvas1.addEventListener('mousemove',
moveit,false);


Set up event handling for the mousemove event

canvas1.addEventListener('mouseup',
finish,false);


Set up event handling for the mouseup event

drawall();


}


function findball(ev) { Function header for mousedown event


var mx; Variable to hold mouse x

Free download pdf