Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Cocos2d Game Development Blueprints

You're reading from   Cocos2d Game Development Blueprints Design, develop, and create your own successful iOS games using the Cocos2d game engine

Arrow left icon
Product type Paperback
Published in Jan 2015
Publisher
ISBN-13 9781783987887
Length 440 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Jorge Jordán Jorge Jordán
Author Profile Icon Jorge Jordán
Jorge Jordán
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Cocos2d Game Development Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Sprites, Sounds, and Collisions FREE CHAPTER 2. Explosions and UFOs 3. Your First Online Game 4. Beat All Your Enemies Up 5. Scenes at the Highest Level 6. Physics Behavior 7. Jump and Run 8. Defend the Tower Index

1-star challenge – collision detection between Dr. Fringe and the UFO


I'm sure you're now an expert at managing collisions, so I think we should detect collisions between our scientist hero and the spaceships or the game will lack realism.

Try to detect these collisions so we can't fly over the whole airspace and make the scientist blink as we did with the yeti in the previous chapter.

The solution

To achieve this challenge, you will need to take advantage of detectCollisions. How it's built makes our task very easy. As we want to detect collisions with UFOs, we will include our code inside the _arrayUFOs loop, and the best place is after this line:

[_arrayLaserGreen removeObjectsInArray:_lasersGreenToRemove];

Paste the following block of code there:

        // Detect ufo-scientist collision
        if (CGRectIntersectsRect(ufo.boundingBox, _scientist.boundingBox)) {
            
            // Blink actions for both fire and scientist
            CCAction *actionDrBlink = [CCActionBlink actionWithDuration...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime
Visually different images