Game Development Reference
In-Depth Information
The initialize function takes the modelMatrix of the grenade as a parameter. The
objective is simple: the explosion has to occur at the same location and orientation
of the grenade in its last frame. Hence, we clone the received model matrix and
simply assign it to the model matrix of the Explosion object. We also initialize the
textureIndex class variable to the first element of the texture array.
Explosion.prototype.initialize=function(modelMatrix) {
this.modelMatrix=mat4.clone(modelMatrix);
this.counter=0;
this.textureIndex=this.textureIndices[0];
this.visible=true;
this.frames=0;
}
The update function increments the counter and assigns the index of the next
texture in the textureIndices array. Once the animation has finished, we toggle
the visibility of the texture.
Explosion.prototype.update=function() {
if(this.counter<this.textureIndices.length){
this.textureIndex=this.textureIndices[this.counter];
this.counter-++;
}
else{
this.visible=false;
this.counter=0;
}
}
We also need to do a small change in the Grenade.js file from the primitive/game
folder of the code bundle.
We need to add a callback function ( explosionCallBack ) to the Grenade class so
that we can pass the model matrix of the grenade in the last frame and initialize
our explosion.
Grenade= inherit(StageObject, function (){
...
this.explosionCallBack=null;
});
 
Search WWH ::




Custom Search