HTML and CSS Reference
In-Depth Information
6.
The next step required is to initialize keyboard input and call both the KeyDown and
KeyUp events inside of the InitObjectManager constructor as follows:
document.onkeydown = function(key){objectManager.keyDown(key);}
document.onkeyup = function(key){objectManager.keyUp(key);}
7.
Once a key is pressed, each of the previously declared events trigger one of two
corresponding functions, which we will now declare below the InitObjectManager
constructor.
this.keyDown = function(event) {
for (obj in this.objects) {
if (this.objects[obj].keyDown)
this.objects[obj].keyDown(event);
}
}
this.keyUp = function(event) {
for (obj in this.objects) {
if (this.objects[obj].keyUp)
this.objects[obj].keyUp(event);
}
}
8. The inal step required is to modify the object manager's Draw function. Replace the
for loop within our Draw function with the modiied loop as follows:
for (obj in this.objects) {
if (this.objects[obj].Update) {
this.objects[obj].Update(deltaTime, this.context, this.deltaX,
this.deltaY);
}
if (this.objects[obj].Draw) {
this.objects[obj].Draw(deltaTime, this.context, this.deltaX, this.
deltaY);
}
}
 
Search WWH ::




Custom Search