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 – detecting if the arrow hits the bird

To make the arrow hit the bird, we need to check that the arrow and the bird are intersecting. After we have found an intersection, we need to remove the bird and the arrow. Let's add the code to perform this:

  1. Open the Bird.h file and add the following method declaration:
    -(void)removeBird:(BOOL)hitByArrow;
  2. Then, open the Bird.m file and add its implementation:
    -(void)removeBird:(BOOL)hitByArrow
    {
        if (hitByArrow)
        {
            CCLOG(@"Bird hit by arrow");
        }
        else
        {
            CCLOG(@"Bird flew away");
        }
        
        [self removeFromParentAndCleanup:YES];
    }
  3. Open the GameScene.m file and add the _arrows array instance variable as follows:
    @implementation GameScene
    {
        //..skipped..
        NSMutableArray *_arrows;
    }
  4. Scroll to the init method and ...
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