(No. 00002) prototype of iOS game genie war (10)

Source: Internet
Author: User

(No. 00002) prototype of iOS game genie war (10)

So far, there has been no returning bullets. If the bullets hit the target or fly out of the screen, there is no need for the bullets to exist.

It does not exist here, instead of deleting it from the screen, because the role of the bullet cache is mentioned above, so it is only possible to set it to invisible here.

First, process the bullets on the fly-out screen. Add the update method to MainScene. m as follows:

-(Void) update :( CCTime) delta {for (CCSprite * bullet in _ bullets) {if (bullet. visible) {if (bullet. position. x <= 0 | bullet. position. x> = 1 | bullet. position. y <= 0 | bullet. position. y> = 1) {bullet. visible = NO; // CCPhysicsBody * physicsBody = bullet. physicsBody; // [physicsBody applyImpulse: ccp (0, 0)] ;}}}

We need to check whether the bullet is flying out of the screen at any time. The judgment logic is simple: directly judge the Coordinate Position of the bullet. because the bullet coordinate type is a percentage type, the overall length and width of the screen are (0, 1). If a bullet flying out of the screen is found, it is invisible.

Another case is that when a bullet hits the target, we will repeat it in the next article ;)

 

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.