Game Development Reference
In-Depth Information
The following callback function,
cameraLocationChanged
, receives the
camera location and sets the message type to
"camera"
. It then invokes the
sendRoomMessage
function:
function cameraLocationChanged(cameraLocationStatus){
cameraLocationStatus.type="camera";
sendRoomMessage(JSON.stringify(cameraLocationStatus));
}
The following
handleKeys
function invokes the
sendRoomMessage
function on both
events of throwing the grenade and firing a bullet with the corresponding
message.
type
value:
function handleKeys(event) {
switch(event.keyCode) {//determine the key pressed
case 13:
leftHand.visible=true;
var message={};
message.type="grenade";
sendRoomMessage(JSON.stringify(message));
break;
case 32://s key
bullets[nextBulletIndex].initialize();
var message={};
message.type="bullet";
message.bulletIndex=nextBulletIndex;
sendRoomMessage(JSON.stringify(message));
...
}
break;
}
}
Open
KeyBoardInteractor.js
from
client/primitive
in your editor. In this class,
we have added a
cameraChangedCallBack
delegate to handle the call back when the
location/direction of camera changes The
KeyBoardInteractor
function is as follows:
function KeyBoardInteractor(camera,canvas){
...
this.cameraChanged=false;
this.cameraChangedCallBack=null;
...
}