Game Development Reference
In-Depth Information
set the radius property anymore, because the images of the SneakyBut-
tonSkinnedBase class determine the radius now. The fireButton is later as-
signed to the skinFireButton.button property, so that the two work together.
Instead of positioning the fireButton , the skinned button is now determining the
position of the button on the screen; the actual fireButton is updated accordingly
by the SneakyButtonSkinnedBase class.
At this point, it makes sense to also write the firing code; Listing 7-12 shows the up-
date method now sending the fire message to the GameScene class. This is also
where the totalTime and nextShotTime variables come into play.
Listing 7-12. Shooting Bullets Whenever the Fire Button Is Active
-(void) update:(ccTime)delta
totalTime + = delta;
GameLayer* game = [GameLayer sharedGameLayer];
Ship* ship = [game defaultShip];
if ( && totalTime > nextShotTime)
nextShotTime = totalTime + 0.5f;
[game shootBulletFromShip:ship];
// Allow faster shooting by quickly tapping the fire button
if ( == NO)
nextShotTime = 0;
The two ccTime variables, totalTime and nextShotTime , are used to limit the
number of bullets the ship will emit to two per second. If the fire button isn't active
(meaning it isn't pressed), the nextShotTime is set to 0 so that the next time you
Search Nedrilad ::

Custom Search