Game Development Reference
In-Depth Information
If the location of the camera changes, the handleKeys function updates the
status variable cameraChanged to true , on each key event. We check whether
the cameraChanged variable is true and whether the handler function has been
assigned, then we create a camera status object with the up, left, position, and
direction vectors. We then invoke the handler function and pass cameraStatus as a
parameter. We also update the cameraChanged variable to false . The handleKeys
function is as follows:
KeyBoardInteractor.prototype.handleKeys=function (event) {
if(event.shiftKey) {
switch(event.keyCode) {//determine the key pressed
case 65://a key
this.cam.roll(-Math.PI * 0.025);//tilt to the left
this.cameraChanged=true;
break;
...
}
...
if(this.cameraChanged==true&&this.cameraChangedCallBack!=null){
var cameraStatus={};
cameraStatus.left=this.cam.left;
cameraStatus.up=this.cam.up;
cameraStatus.dir=this.cam.dir;
cameraStatus.position=this.cam.pos;
this.cameraChangedCallBack(cameraStatus);
this.cameraChanged=false;
}
}
Summary
In this chapter, we first covered the implementation of the canvas 2D context
as texture in our game scene. This is a very powerful tool, not just limited to
game development, but is also used in many 3D applications such as product
customization tools. The canvas 2D API offers a very powerful list of functions to
manipulate images using its pixel data. This gives us the ability to add dynamic
textures to our game scene.
 
Search WWH ::




Custom Search