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)