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.
- Open the
Hunter.h
file and add theaimAtPoint:
method declaration:#import "CCSprite.h" @interface Hunter : CCSprite -(void)aimAtPoint:(CGPoint)point; @end
- Then, open the
Hunter.m
file and add the following methods below theinit
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 ...
Get Learning iPhone Game Development with Cocos2D 3.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.