Time for action – shooting the arrow
Here is the fun part. We're going to shoot the arrow:
Open the
Hunter.h
header file and add the following method declaration after theaimAtPoint:
method declaration:-(CCSprite*)shootAtPoint:(CGPoint)point;
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...