Open Arm.h and add a new method to its interface:
-(void)armShoot;
Next, implement this method in ARM.M:
-(void)armShoot{ CGPoint startPoint = [self convertToWorldSpace:ccp(05)]; CGPoint endPoint = [self convertToWorldSpace:ccp(205)]; [_mainScene shoot:startPoint to:endPoint];}
The method eventually calls the shoot method in Mainscene, before which Armshoot obtains the trajectory of the bullet. The trajectory is determined by the starting and ending points, because the trajectory of the bullet is determined by the physical engine, so the final actual shot is a parabola.
As mentioned in the previous arm rotation application Lidian weights in the center of the arm and the focus of the hand, as well, the trajectory of the bullet is also coincident with Arm's midline:
So when is the bullet fired? There are many options, such as creating a launch button on the screen and firing bullets when clicked.
Here's a simpler way: firing bullets at the end of a player's touch:
-(void)touchEnded:(CCTouch *)touch withEvent:(CCTouchEvent *)event{ [self armShoot];}
Do the same in the Armstatic class. Here is a bad example, because there are duplicate code. If you write a program that also has a variety of sins, then code duplication is a "capital offense"!
But the first sentence of "Innocence", because the cat is also reconstructed, although you do not necessarily see;)
Compile and run, the effect of the launch is as follows:
Please ignore the middle of those squares and baskets, don't worry! They're going to be on the way;)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
(no.00003) iOS games simple robot projection game forming (10)