The Essential Guide to HTML5

(Greg DeLong) #1

CHAPTER 7


Code Explanation


} Close clause


curwall = new
Wall(mx,my,mx+1,my+1,wallwidth,wallstyle);


Create new wall. It is small at this point.

inmotion = true; Set inmotion to true


everything.push(curwall); Add curwall to everything


drawall(); Draw everything


} Close function


function stretchwall(ev) { Function header stretchwall to that
uses the dragging of the mouse to
stretch out a wall while the mouse is
dragged.


if (inmotion) { Check if inmotion


var mx; Hold mouse x


var my; Hold mouse y


if ( ev.layerX || ev.layerX == 0) { Can we use layerX?


mx= ev.layerX; Set mx


my = ev.layerY; Set my


} else if (ev.offsetX
|| ev.offsetX == 0) {


Else can we use offsetX? This is
necessary for different browsers.

mx = ev.offsetX; Set mx


my = ev.offsetY; Set my


} Close clause


curwall.fx = mx; Change curwall.fx to mx


curwall.fy = my; Change curwall.fy to my

Free download pdf