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