HTML and CSS Reference
In-Depth Information
The mouseUp functionfindsthecurrent x and y positionofthemousepointerinasimilarfash-
ion to how we have done it previously in this topic. (See Chapter 6 .) Then, using a “hit test
Point”collision detection (again,aswesawin Chapter 6 ),wechecktoseewhetherthemouse
was clicked on any of the items in objectList . If so, it calls that object's mouseUp() func-
tion:
this
this . onMouseUp = function
function ( event ) {
var
var x ;
var
var y ;
iif ( event . pageX || event . pageY ) {
x = event . pageX ;
y = event . pageY ;
} else
else {
x = e . clientX + document . body . scrollLeft +
document . documentElement . scrollLeft ;
y = e . clientY + document . body . scrollTop +
document . documentElement . scrollTop ;
}
x -= this
this . theCanvas . offsetLeft ;
y -= this
this . theCanvas . offsetTop ;
var
var mouseX = x ;
var
var mouseY = y ;
for
for ( i = 0 ; i < this
this . objectList . length ; i ++ ) {
var
var to = this
this . objectList [ i ];
iif ( ( mouseY >= to . y ) && ( mouseY <= to . y + to . height )
&& ( mouseX >= to . x ) && ( mouseX <=
to . x + to . width ) ) {
to . onMouseUp ( mouseX , mouseY );
}
}
}
You can see the final code listing in DisplayList.js in the code distribution.
GameUtilities.js
GameUtilities.js is where we will put our debugger function and our check for can-
vasSupport() . In the future, you could plan to put any utility functions in here that do not
need to exist in a class.
var
var Debugger = function
function () { };
Debugger . log = function
function ( message ) {
Search WWH ::




Custom Search