Book Image

Learning iPhone Game Development with Cocos2D 3.0

By : Kirill Muzykov
Book Image

Learning iPhone Game Development with Cocos2D 3.0

By: Kirill Muzykov

Overview of this book

Table of Contents (19 chapters)
Learning iPhone Game Development with Cocos2D 3.0
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – shooting the arrow


Here is the fun part. We're going to shoot the arrow:

  1. Open the Hunter.h header file and add the following method declaration after the aimAtPoint: method declaration:

    -(CCSprite*)shootAtPoint:(CGPoint)point;
  2. Then, open the Hunter.m file and add the following implementation part of this method:

    -(CCSprite*)shootAtPoint:(CGPoint)point
    {
        //1
        [self aimAtPoint:point];
        
        //2
        CCSprite *arrow = 
          [CCSprite spriteWithImageNamed:@"arrow.png"];
        
        //3
        arrow.anchorPoint = ccp(0, 0.5f);
        
        //4
        CGPoint torsoCenterGlobal = 
          [self torsoCenterInWorldCoordinates];
        arrow.position = torsoCenterGlobal;
        arrow.rotation = _torso.rotation;
        
        //5
        [self.parent addChild:arrow];
        
        //6
        CGSize viewSize = [CCDirector sharedDirector].viewSize;
        CGPoint forwardVector = ccp(1.0f, 0);
        
        float angleRadians =
          -1 * CC_DEGREES_TO_RADIANS(_torso.rotation);
        CGPoint arrowMovementVector =
          ccpRotateByAngle...