(No. 00005) iOS game for the explosive bullet player (10): Game protagonist (3)

Source: Internet
Author: User

(No. 00005) iOS game for the explosive bullet player (10): Game protagonist (3)

The original or translated works of the giant panda and pig hope. You are welcome to reprint them. Please indicate the source for reprinting.
If you think it is not easy to write, Please give more comments. If you think it is good, please give more support. Thank you! Hopy ;)

Next, let's take a look at several methods of playing special animations in the game's main character class, starting with runWinAnimation:

// Animation for running the genie celebration-(void) runWinAnimation {CCActionJumpBy * jump = [CCActionJumpBy actionWithDuration: 5 position: ccp (0, 5) height: 5 jumps: 10]; [self runAction: [CCActionRepeatForever actionWithAction: jump]; [self runAnimation: _ happyAnimation];}

The animation is played when the main character finds it in the game scene and enters the exit. The code is very simple, that is, the main character jumps and runs _ happyAnimation to represent the celebration animation. the animation was created in advance in the initialization method of the main character.

When the main character crashes, especially when it is hit by the flame genie or when it is bombed, we will play the fired Animation:

// Run the spontaneous combustion animation-(void) fired {if (_ isDead) {return;} _ isDead = YES; [self stopAllActions]; CCActionAnimate * animate = [CCActionAnimate actionWithAnimation: _ firedAnimation]; CCActionDelay * delay = [CCActionDelay actionWithDuration: 0.3]; CCActionCallBlock * block = [CCActionCallBlock actionWithBlock: ^ {self. visible = NO;}]; CCActionSequence * seq = [CCActionSequence actions: animate, delay, block, nil]; [self runAction: seq];}

If the main character is down, return directly. Otherwise, set the death state of the main character, stop all actions, adjust the animation running interval and serial sequence action according to the game logic, and finally run the sequence action.

Two methods are mentioned in the interface file of the main class:

-(BOOL)isInvincible;-(void)setIsInvincible:(BOOL)isInvincible;

Maybe it is better to think about making them into a property? However, we need to add operations in the writer method, so we must implement the writer method by ourselves:

-(BOOL) isinvincvisible {return _ isinvincvisible;} // The automatically generated property-(void) setisinvincvisible :( BOOL) isinvincvisible {_ isinvincvisible = isinvincvisible because additional operations are required; [self setIsRiding: isInvincible];}

As you can see, in addition to adjusting the _ isInvincible variable of the main character in the writer method, I also called another setIsRiding method:

-(Void) setIsRiding :( BOOL) isRiding {_ isRiding = isRiding; CCSpriteFrame * spriteFrame; // if the current status is riding, set the sprite frame to the corresponding image in the forward direction. // ERROR: When the status changes to riding status, the genie must be in the mobile process (only invincible items can be touched during the movement), so you only need to judge the current animation. // Add the drag-and-drop item, here we also need to judge two cases as follows: if (isRiding) {if (_ curAnimation ==_facingforwardanimation | _ curDirection = RoleDirectionDown) {spriteFrame = [CCSpriteFrame frameWithImageNamed: @ "inline"];} else if (_ curAnimation = _ facingBackAnimation | _ curDirection = RoleDirectionUp) {spriteFrame = [CCSpriteFrame frameWithImageNamed: @ "inline"];} else if (_ curAnimation ==_facingleftanimation | _ curDirection = RoleDirectionLeft) {spriteFrame = [CCSpriteFrame frameWithImageNamed: @ "bm_rideLeft_2.png"];} else if (_ curAnimation ==_facingrightanimation | _ curDirection = RoleDirectionRight) {spriteFrame = [CCSpriteFrame frameWithImageNamed: @ "bm_rideRight_2.png"];} else {// otherwise, the genie will be in a non-cycling status, and the genie will be restored in the forward direction) you need to determine two situations: // 1. the genie is in the "move" status. 2. restore status when the genie is in the static state // determine the two situations and handle them separately. if (_ curAnimation ==_ facingForwardRideAnimation | _ curDirection = RoleDirectionDown) {spriteFrame = [CCSpriteFrame frameWithImageNamed: @ "bm_forward_2.png"];} else if (_ curAnimation ==_ facingBackRideAnimation | _ curDirection = RoleDirectionUp) {spriteFrame = [CCSpriteFrame frameWithImageNamed: @ "bm_back_2.png"];} else if (_ curAnimation ==_facingleftrideanimation | _ curDirection = roledireleft left) {spriteFrame = [CCSpriteFrame frameWithImageNamed: @ "bm_left_2.png"];} else if (_ curAnimation ==_ facingRightRideAnimation | _ curDirection = RoleDirectionRight) {spriteFrame = [CCSpriteFrame frameWithImageNamed: @ "bm_right_2.png"];} else {}}// stop the current animation [self stopAction: _ curAnimate]; // you can specify the appropriate sprite frame self. spriteFrame = spriteFrame ;}

The comment above is clear enough that the function of this method is to change the animation of the protagonist's movement when it is invincible, so that it can ride on a mount, A little domineering ;)

The following are the effects of an invincible protagonist:

The main character of the game is basically introduced here. Let's take a look at the various monsters in the game. see you later ;)

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.