Chipmunk the emergence and resolution of zombie physical objects (v)

Source: Internet
Author: User
Tags addchild

, because the code to get the bounce rods to grow and shorten is similar, so we'll just look at one, so let's take a closer look at the shortened 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;[Physicsworld Removechild:stick Cleanup:yes];[Physicsworld Addchild:sticknormal];Gamescene. Stickingamescene= Sticknormal;Return;}} cgpoint Position = Stick. Position;__block Stick *stickshorter;@synchronized (gamescene) {stickshorter = [Stick Stickshorter];[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];Stickshorter = Nil;[Physicsworld Addchild:sticknormal];Gamescene. Stickingamescene= Sticknormal;}} Delay:Ten];}

The code is long, so let's look at it in turn.

First, an instance of Gamescene and the physical world object is obtained.

If the current stick is already short, it can no longer be shortened, so the direct exit method
If the current stick is a long stick, delete the stick and create a new normal-length stick. Equivalent to a long stick hit the shorter pentagram to return to normal size, and then exit the method.

Otherwise, the current should be the normal size of the stick need to shorten it, the practice is:

1. First create a short stick in the original stick position, but set it to be invisible, because there is also a shorter animation effect;
2. Create a stick node without a physical object and perform a shorter animation;
3. Delete itself at the end of the animation and make the short stick visible. Note that animation time needs to be moderate, neither too long nor too short. This will be detailed in the iOS Game Development Series blog post.
4. Add a block with a delay of 10 seconds to the short stick, delete it after 10 seconds, and create a new normal size stick in the original location. Equivalent to restoring the normal size of the stick after 10 seconds.

The above is the relevant function code.

Compile and run the app. Occasionally a "zombie stick" is generated on the screen while the game is running, which says that the object cannot be found in the physical world and is not deleted.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Chipmunk the emergence and resolution of zombie physical objects (v)

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.