Game Development Reference
In-Depth Information
When the
Grenade
animation finishes, it invokes the
explosionCallBack
function
and passes its
modelMatrix
as shown in the following code:
Grenade.prototype.update=function() {
if(this.counter<this.positions.length-1){
...
}
else{
...
if(this.explosionCallBack!=null){
this.explosionCallBack(this.modelMatrix);
}
}
}
Let's walk through the implementation of the preceding classes in
06-Grenade-
Action-Blast.html
.
We have added a new variable to hold the explosion object, as shown in the
following code:
var explosion=null;
In the
loadStageObject
function, after the
grenade
object is created, we assign the
name of the callback function (
initializeExplosion
) to the
explosionCallBack
property of the
grenade
object. It is invoked once its animation has finished. After
the
explosion
object is created, we invoke
initExplosionTextures
to load all the
textures shown previously.
function
loadStageObject(url,location,rotationX,rotationY,rotationZ){
...
else if(nameOfObject=="grenade"){
stageObject=new Grenade();
grenade=stageObject;
grenade.explosionCallBack=initializeExplosion;
}else if(nameOfObject=="explosion"){
stageObject=new Explosion();
explosion=stageObject;
initExplosionTextures();
}
...
}