(NO.00003) iOS games simple robot projection game forming notes (10)
Open Arm. h and add a new method to its interface:
-(void)armShoot;
Next we will implement this method in Arm. m:
-(void)armShoot{ CGPoint startPoint = [self convertToWorldSpace:ccp(0, 5)]; CGPoint endPoint = [self convertToWorldSpace:ccp(20, 5)]; [_mainScene shoot:startPoint to:endPoint];}
This method finally calls the shoot method in MainScene. Before that, armShoot obtained the trajectory of the bullet. the trajectory is determined by the starting point and the ending point. Because the trajectory of the bullet is determined by the physical engine, a parabolic curve is finally triggered.
As mentioned above, the rotation force of the Arm points in the midline of the Arm and the focus of the hand. Similarly, the bullet shot track also coincides with the midline of the Arm:
So when will the bullet be fired? There are many options, such as creating a launch button on the screen and launching a bullet when you click it.
A simple method is used here: the bullet is fired when the player's touch ends: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4NCjxwcmUgY2xhc3M9 "brush: java;"> -(void)touchEnded:(CCTouch *)touch withEvent:(CCTouchEvent *)event{ [self armShoot];}
Perform the same operation in the ArmStatic class. This is a bad example, because there are repeated code. If there are also various sins in programming, code repetition is "death "!
But I am not guilty here, because this cat still needs to be restructured, although you may not be able to see it ;)
Compile and run the program. The emission effect is as follows:
Ignore the boxes and baskets in the middle. Don't worry! They will be mentioned soon ;)