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

Source: Internet
Author: User

The first is to touch the code that moves the bounce stick:

-(void)touchMoved:(CCTouch *)touch withEvent:(CCTouchEvent *)event{    CGPoint location = [[CCDirector sharedDirector] convertTouchToGL:touch];    @synchronized(self){        [self.stickInGameScene moveStickTo:location];    }}

For simplicity, the implementation of the specific invocation method is not given, and you can get an overview of the actual functionality by means of the method name. I'll explain where I need to be.

The above code moves the stick (bounce stick) to the location and synchronizes because you want to make sure that the stick instance value is not modified at some point.

The former said that stick different state of the corresponding physical objects are different, in the game process stick can be modified at any time, so here to do synchronization.

When a ball hits a brick we have to create a pentagram in the corresponding collision callback method:

-(BOOL)ccPhysicsCollisionBegin:(CCPhysicsCollisionPair *)pair ball:(CCNode *)ball brick:(CCNode *)brick{    //...    [Star spawnStar:(Brick*)brick];    //...    return YES;}

Ignoring extraneous code, take a look at the Spawnstar method and note that it is a class method:

//generate the corresponding star according to the Bricks+(void) Spawnstar: (brick*) brick{Star *star;Switch(Brick. Brickcolor) { CaseBrkcoloryellow:star = [Star Starwithtype:startypesticklonger]; Break; CaseBrkcolorred:star = [Star Starwithtype:startypestickshorter]; Break; CaseBrkcolormax: CaseBrkcolorunknown:nsassert (NO, @"Error Brick color!"); Break;//The star is not generated by default and is returned directly        default:return; Break; }//Omit extraneous code}

The code logic is clear:

Yellow bricks produce startypesticklonger pentagram, red bricks produce startypestickshorter pentagram.

Let's take a look at the handling code of the pentagram and the bounce stick when in contact;)

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

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

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.