Saturday 12 January 2013

Tank Rampage's Tank 4- destruction


            When the tank’s health reaches zero, 
the following method is called:
-(void)tankDestroyed{
    for (LHJoint*joint in [lh jointsWithTag:TANK]) {
        [joint removeSelf];
    }
    for (LHJoint*wheelJoint in WheelArray) {
    
        [wheelJoint removeSelf];
    }
    
    [WheelArray removeAllObjects];
    
    for (__strong LHSprite*trackPart in TrackArray) {
        [trackPart pauseAnimation];
        trackPart=nil;
    }
    [TrackArray removeAllObjects];
    
    [WheelArray removeAllObjects];

   
    barrel=nil;
    
    for (LHSprite*tankPart in [lh spritesWithTag:TANK]) {
        [tankPart setCollisionFilterMask:1];
        [tankPart setCollisionFilterCategory:4];
        [tankPart setCollisionFilterGroup:-4];    }
}


First, all joints attached to the tank (that have the tag tank), will all be destroyed. All arrays that contained joints and objects are emptied, as keeping them would cause the objects to not be removed properly and might even cause a crash. All animations are stopped and the bodies’ collision bits are changed so they all collide with the level. The result is an exploding tank, with pieces flying everywhere.
Game Over!
This article is the final part of a small 4-piece series on the tank of Tank RampagePlease let me know if you want any more info on this subject, or perhaps a tutorial?

No comments:

Post a Comment