Skip to Main Content
Learning iPhone Game Development with Cocos2D 3.0
book

Learning iPhone Game Development with Cocos2D 3.0

by Kirill Muzykov
June 2014
Beginner to intermediate content levelBeginner to intermediate
434 pages
9h 49m
English
Packt Publishing
Content preview from Learning iPhone Game Development with Cocos2D 3.0

Time for action – aiming at the touch position

Now that we can point where to shoot, let's make the hunter to aim at this point.

  1. Open the Hunter.h file and add the aimAtPoint: method declaration:
    #import "CCSprite.h"
    
    @interface Hunter : CCSprite
    
    -(void)aimAtPoint:(CGPoint)point;
    
    @end
  2. Then, open the Hunter.m file and add the following methods below the init method:
    -(CGPoint)torsoCenterInWorldCoordinates { //1 CGPoint torsoCenterLocal = ccp(_torso.contentSize.width / 2.0f, _torso.contentSize.height / 2.0f); //2 CGPoint torsoCenterWorld = [_torso convertToWorldSpace:torsoCenterLocal]; return torsoCenterWorld; } -(float)calculateTorsoRotationToLookAtPoint: (CGPoint)targetPoint { //1 CGPoint torsoCenterWorld = [self torsoCenterInWorldCoordinates]; //2 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Swift Games Development for iOS: Develop 2D and 3D games Using Apple's SceneKit and SpriteKit

Beginning Swift Games Development for iOS: Develop 2D and 3D games Using Apple's SceneKit and SpriteKit

James Goodwill, Wesley Matlock

Publisher Resources

ISBN: 9781782160144Supplemental Content