Game Development Reference
In-Depth Information
bullets.push(bullet);
stage.addModel(bullet);
}
}
}
In the handleKeys function, we simply pick a bullet from the array referenced by
the nextBulletIndex variable. The value of the variable is 0 initially. After that, we
increment the next bullet index, and if the counter has exceeded the length of the
bullets array, then we initialize it back to 0.
function handleKeys(event) {
switch(event.keyCode) {//determine the key pressed
case 32://space key
bullets[nextBulletIndex].initialize();
nextBulletIndex++;
if(nextBulletIndex>=bullets.length){
nextBulletIndex=0;
}
break;
}
}
In the preceding code, we used a very simple algorithm to pick bullets from the
pool. We only used the next index of the last active bullet. We could use simple logic
currently because we know that by using the next index, we are actually using the
bullet that was either never used or was the oldest one to be used (circular) as the life
of each object is the same. In other games, we might have to use more complicated
logic to re-use objects because the life of each object may vary.
Using B-spline interpolation for grenade
action
In this section, we will introduce the left hand. The left hand will be used to throw
the grenade. So, first we will need to create a linear animation of the left hand.
However, this time, we will not interpolate over position but over rotation. Then, we
will chain animations. When the animation of the left hand ends, we will start the
animation of the grenade.
 
Search WWH ::




Custom Search