(No. 00004) implementing the brick-hitting game for iOS (13th): It is scalable and I am a golden hoop (bottom )!

Source: Internet
Author: User

(No. 00004) implementing the brick-hitting game for iOS (13th): It is scalable and I am a golden hoop (bottom )!

 

Prepare materials for shortening the bounce stick

Similar to the previous article, we have developed a material that shortens the size of the rebound rod.

Open SpriteBuilder, create the StickShorter. ccb file, and draw its sprite frame and physical object as follows:

Vc/y0rK74bHktPMs1eK + zbK7ysfO0sPHz + vSqrXEwcsuPC9wPg0KPGgyIGlkPQ = "Create a shortened item Star"> Create a shortened item star

We use red stars to shorten the item, so spawStar writes the following:

case brkColorRed:            star = [Star starWithType:starTypeStickShorter];            break;

In GameScene. m, add the following code to the code for the collision between stars and bounce Rods:

case starTypeStickShorter:            @synchronized(self){                [self scheduleBlock:^(CCTimer *timer){                    [Star doStickShorterWork:self.stickInGameScene];                } delay:0];            }            break;

Now, let's go back to Star. m and add the doStickShorterWork method:

+(void)doStickShorterWork:(Stick *)stick{    GameScene *gameScene = [GameScene sharedGameScene];    CCPhysicsNode *physicsWorld = (CCPhysicsNode*)stick.parent;    @synchronized(gameScene){        if ([stick.name isEqualToString:@stickShorter]) {            return;        }        if ([stick.name isEqualToString:@stickLonger]) {            Stick *stickNormal = [Stick stickNormal];            stickNormal.position = stick.position;            [stick removeFromParent];            //[physicsWorld removeChild:stick cleanup:YES];            [physicsWorld addChild:stickNormal];            gameScene.stickInGameScene = stickNormal;            return;        }    }    CGPoint position = stick.position;    __block Stick *stickShorter;    @synchronized(gameScene){        stickShorter = [Stick stickShorter];        [stick removeFromParent];        //[physicsWorld removeChild:stick cleanup:YES];        stickShorter.position = position;        [physicsWorld addChild:stickShorter];        stickShorter.visible = NO;        gameScene.stickInGameScene = stickShorter;        CCSprite *stickNode = (CCSprite*)[CCBReader load:@Elements/StickNode];        stickNode.position = stickShorter.position;        [gameScene addChild:stickNode z:50];        CCActionScaleTo *shorterAction = [CCActionScaleTo actionWithDuration:0.4f scaleX:0.5f scaleY:1.0f];        CCActionCallBlock *blk = [CCActionCallBlock actionWithBlock:^{            [stickNode removeFromParent];            stickShorter.visible = YES;        }];        CCActionSequence *seq = [CCActionSequence actions:shorterAction,blk,nil];        [stickNode runAction:seq];    }    [stickShorter scheduleBlock:^(CCTimer *timer){        @synchronized(gameScene){            Stick *stickNormal = [Stick stickNormal];            stickNormal.position = stickShorter.position;            [stickShorter removeFromParent];            [physicsWorld addChild:stickNormal];            gameScene.stickInGameScene = stickNormal;        }    } delay:10];}

You can compare it with the variable-length code, which is basically the same.

Compile and run the game as follows:

You can add more special effects in shortening and increasing length. Open the brain hole, kids shoes ;)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.