Game Development Reference
In-Depth Information
Understanding the main flow code
Open the
10-2D-Sprites-And-Text.html
file from the
client
folder in your
favorite editor.
We have only changed our
loadStageObject
function to add our
ModelSprite
class. Once our
RiggedMesh
class is loaded, we initialize our
ModelSprite
class with
our
RiggedMesh
class' object and the
camera
class' object. We set
deltaY
to render
the sprite of 16 units above the model. We then add the texture to the texture array in
the
stage
object.
Remember that we store textures and
stageObject
in the main
stage
object. The
textures are mapped to
stageObject
with
textureIndex
. We did this so that if
multiple objects use the same texture, then we do not load them multiple times, as
explained in
Chapter 6
,
Applying Textures and Simple Animations to Our Scene
. The
following code explains the
loadStageObject
function:
function loadStageObject(url,location,rotationX,rotationY,
rotationZ ){
//The relevant code changes …......................
if(data.bones){
stageObject=new RiggedMesh();
var sprite=new ModelSprite(stageObject,cam);
sprite.deltaY=16;
sprite.drawText("Mr. Red");
stage.addTexture(sprite.textureIndex,sprite.canvasId,
document.getElementById(sprite.canvasId),true,true);
stage.addModel(sprite);
}
//The relevant code changes...
}
Communicating in real time
Real-time communication is a problem that web developers have been trying to solve
for a very long time. The problem is that the client can ping the web server, but the
server cannot contact the client. The reason is that the client requests a web page,
the server sends the response and the socket is closed. Although the HTTP 1.1 uses
persistent connections for multiple requests response, it times out after a specified
time. The directive behind a persistent connection is HTTP keep-alive.