(no.00004) iOS implementation brick game (13): retractable freely, I am Ruyi Golden cudgel (under)!

Source: Internet
Author: User

Panda Pig • Patty original or translated works. Welcome reprint, Reprint please indicate the source.
If you feel that the writing is not good please tell me, if you feel good please support a lot of praise. Thank you! Hopy;)

Prepare to shorten rebound bar material

Similar to the previous one, we followed the same material as a shortened rebound stick.

Open Spritebuilder, create a new STICKSHORTER.CCB file, press to draw its sprite frame and physical object:

Note that when you zoom in and out of the original bounce stick in AI, just zoom in one Direction along the x-axis, or the y-axis will become larger, which is not what we want.

Create a shortened prop star

We use the Red stars to shorten the props, so it's written in Spawstar:

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

In GAMESCENE.M, in the code where the Stars collide with the bounce stick, add the following code:

casestarTypeStickShorter:            @synchronized(self){                [selfscheduleBlock:^(CCTimer *timer){                    [StardoStickShorterWork:self.stickInGameScene];                delay:0];            }            break;

Well, finally, 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. Nameisequaltostring:@"Stickshorter"]) {return;} if ([Stick. Nameisequaltostring:@"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:sticknodeZ: -];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 = [Stic K Sticknormal];Sticknormal. Position= Stickshorter. Position;[Stickshorter Removefromparent];[Physicsworld Addchild:sticknormal];Gamescene. Stickingamescene= Sticknormal;}} Delay:Ten];}

We can compare with the variable length of the corresponding code, the basic is the same.

The following compile runs the game, the effect is as follows:

You can add more effects in shorter and longer lengths, open your brain hole, kids ' shoes;)

(no.00004) iOS implementation brick game (13): retractable freely, I am Ruyi Golden cudgel (under)!

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.