(NO.00003) iOS games simple robot projection game forming notes (10)

Source: Internet
Author: User

(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 ;)

 

Related Article

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.