Cocos2d for iPhone 0.99 Beginner's Guide


Cocos2d for iPhone 0.99 Beginner's Guide
eBook: $23.99
Formats: PDF, PacktLib, ePub and Mobi formats
$20.39
save 15%!
Print + free eBook + free PacktLib access to the book: $63.98    Print cover: $39.99
$39.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Reviews
Support
Sample Chapters
  • A cool guide to learning cocos2d with iPhone to get you into the iPhone game industry quickly
  • Learn all the aspects of cocos2d while building three different games
  • Add a lot of trendy features such as particles and tilemaps to your games to captivate your players
  • Full of illustrations, diagrams, and tips for building iPhone games, with clear step-by-step instructions and practical examples

Book Details

Language : English
Paperback : 368 pages [ 235mm x 191mm ]
Release Date : December 2010
ISBN : 1849513163
ISBN 13 : 9781849513166
Author(s) : Pablo Ruiz
Topics and Technologies : All Books, Mobile Application Development, iOS, Beginner's Guides, Games, Web Graphics & Video

Table of Contents

Preface
Chapter 1: Getting Started with Cocos2d
Chapter 2: Playing with Sprites
Chapter 3: Let's Do Some Actions
Chapter 4: Pasting Labels
Chapter 5: Surfing through Scenes
Chapter 6: Menu Design
Chapter 7: Implementing Particle Systems
Chapter 8: Familiarizing Yourself with Tilemaps
Chapter 9: Playing Sounds with CocosDenshion
Chapter 10: Using Physics Engines
Chapter 11: Integrating OpenFeint
Appendix: Pop Quiz Answers
Index
  • Chapter 1: Getting Started with Cocos2d
    • Downloading Cocos2d for iPhone
    • Time for action – opening the samples project
    • Installing the templates
    • Time for action – installing the templates
    • Creating a new project from the templates
    • Time for action – creating a HelloCocos2d project
    • Managing the game with the CCDirector
      • Types of CCDirectors
    • Time for action – taking a first look at the
    • HelloCocos2dAppDelegate
      • Scene management
    • Doing everything with CCNodes
    • Time for action – peeking at the HelloWorldScene class
      • CCNodes properties
      • Handling CCNodes
    • Checking your timing
    • Time for action – using timers to make units shoot each second
      • Delaying a method call
    • Time for action – destroying your units
    • Debugging cocos2d applications
    • Time for action – checking Cocos2d debug messages
    • Time for action – checking deallocing messages
    • Time for action – knowing your errors
    • Time for action – removing debug messages
    • Summary
    • Chapter 2: Playing with Sprites
      • Making a puzzle game
      • Beginning a new project
      • Time for action – creating a new project
      • Displaying images with CCSprites
      • Time for action – adding a background image to the game
        • Creating CCSprites
          • Pixel formats
          • More ways of creating CCSprites
      • Time for action – creating the Stone class
      • Creating the game board
      • Time for action – placing stones in the grid
      • Interacting with sprites
      • Time for action – registering the stones for receiving touches
      • Time for action – handling touches for swapping stones
      • Time for action – swapping the stones around
      • Time for action – checking for matches
      • Making them fall!
      • Time for action – refilling the grid
        • Analyzing the logic
      • Playing with CCSprite's properties
      • Time for action – making a time bar
      • Changing a sprite's texture at runtime
      • Time for action – changing textures on the fly
        • The CCTextureCache
      • Using Spritesheets
      • Time for action – creating sprites from Spritesheets
      • Creating Spritesheets with zwoptex
      • Time for action – creating more colored stones
      • with Spritesheets
      • Preloading images
      • Time for action – preloading your images
      • Making OpenGl Calls
      • Time for action – selecting a stone for swapping
      • Summary
      • Chapter 3: Let's Do Some Actions
        • Basic actions
        • Time for action – animating the stone falling
          • Using other basic actions
        • Time for action – destroying stones with actions
        • Time for action – tinting the time bar
        • Composition actions
        • Time for action – making a nice disappear effect
          • More composition actions
        • Time for action – making stones fall and grow
        • Time for action – animating the grid
        • Ease actions
        • Time for action – modifying animations with ease actions
        • Effect actions
        • Time for action – making the background shake when
        • matching five stones
          • Applying a single action to multiple CCNodes
        • Special actions
        • Time for action – ready, set, go!
          • Using CCCallFuncND
        • Time for action – telling the player he lost
        • Animations
        • Time for action – animating the stones
          • CCSpriteFrame and the CCSpriteFrameCache
          • The CCAnimation class
        • Summary
        • Chapter 4: Pasting Labels
          • Using CCLabels
          • Time for action – first time tutorials
          • Displaying texts with CCLabelAtlas
          • Time for action – displaying and updating scores with
          • CCLabelAtlas
          • Creating texts with CCBitmapFontAtlas
          • Time for action – showing feedback
          • Time for action – running actions on texts
          • Making your own BitmapFontAtlas with BM Font tool
          • Time for action – creating your own Bitmap font
          • Wrapping up the game
          • Summary
          • Chapter 5: Surfing through Scenes
            • Aerial Gun, a vertical shooter game
            • Creating new scenes
            • Time for action – creating the splash and main menu scene
            • Transitioning through scenes
            • Time for action – moving through scenes in a nice way
            • Implementing the game logic
              • Preparing for the game
              • Making a hero
            • Time for action – creating the hero class
              • Making yourself some enemies
            • Time for action – throwing enemies at your hero
              • Forging some bullets
            • Time for action – creating and reusing bullets
            • Handling accelerometer input
            • Time for action – moving your hero with the accelerometer
            • Handling touches on layers
            • Time for action – firing the bullets
            • Detecting collisions
            • Time for action – shooting down your enemies
            • Time for action – losing your life
            • Adding more layers to scenes
            • Time for action – creating a HUD to display lives and the score
            • Time for action – creating a pause menu
            • Time for action – pausing the game while inactive
            • Summary
            • Chapter 6: Menu Design
              • Creating a simple menu
              • Time for action – adding a menu with texts to the main scene
              • Using image menu items
              • Time for action – adding a difficulty selection screen
              • Animating menu items
              • Time for action – animating the main menu
              • Using toggle menu items
              • Time for action – creating the options menu
              • Saving and loading preferences
              • Time for action – persisting options data
              • Summary
              • Chapter 7: Implementing Particle Systems
                • Taking a look at the prebuilt particle systems
                • Time for action – running the particle test
                • Time for action – analyzing the ParticleMeteor system
                  • Particle system properties
                • Implementing particle systems in your game using Gravity mode
                  • CCPointParticleSystem
                  • CCQuadParticleSystem
                • Time for action – making bombs explode
                • Using the radius mode
                • Time for action – hurting your enemies
                  • Changing the way particle systems move
                • Using Particle Designer to create particle systems
                • Time for action – creating a smoke trail
                • Summary
                • Chapter 8: Familiarizing Yourself with Tilemaps
                  • Using tilemaps
                  • Creating tilemaps with Tiled
                  • Time for action – creating your first map
                  • Loading tilemaps in Cocos2d
                  • Time for action – using tilemaps in Cocos2d
                  • Time for action – running actions on layers
                  • Time for action – reaching the end of the level
                  • Time for action – fixing black gaps and glitches
                  • Using layers to hold objects
                  • Time for action – adding object layers in tiled
                  • Time for action – retrieving objects in Cocos2d
                  • Summary
                  • Chapter 9: Playing Sounds with CocosDenshion
                    • What is CocosDenshion?
                    • Getting started with sounds
                    • Time for action – using SimpleAudioEngine
                      • Methods for handling sound effects
                    • Time for action – playing background music with
                    • SimpleAudioEngine
                      • Methods for handling background music
                    • Using CDSoundEngine
                    • Time for action – setting it up
                    • Time for action – playing sound effects for explosions
                    • Time for action – loading effects asynchronously with
                    • CDSoundEngine
                    • Time for action – playing background music with
                    • CDAudioManager
                    • Summary
                    • Chapter 10: Using Physics Engines
                      • A word about physics engines
                        • Box2d
                        • Chipmunk
                        • So, which one should I use?
                      • Totem balance, a physical game
                      • Time for action –taking a look at the Chipmunk template
                        • Understanding cpBodies and cpShapes
                      • Preparing the game
                      • Bringing objects to life
                        • The Totem
                      • Time for action – creating a poly-shaped object
                      • Time for action – creating the goal platform
                        • Removable blocks
                      • Time for action – building blocks
                      • Time for action – destroying shapes with touch
                      • Collision callbacks
                      • Time for action –losing the game
                      • Time for action –winning the game
                      • Placing static shapes
                      • Summary
                      • Chapter 11: Integrating OpenFeint
                        • Signing up and downloading the SDK
                        • Time for action – signing up and downloading the SDK
                        • Integrating OpenFeint into your game
                        • Time for action – making OpenFeint work
                        • Time for action – displaying the OpenFeint dashboard
                        • Adding leaderboards to your game
                        • Time for action – creating a leaderboard
                        • Adding achievements to your game
                        • Time for action – creating an achievement
                        • Submitting your game for OpenFeint approval
                        • Summary
                        • Appendix: Pop Quiz Answers
                          • Chapter 2:
                            • Playing with Sprites
                          • Chapter 3:
                            • Let’s do some actions
                          • Chapter 4:
                            • Pasting labels
                          • Chapter 5:
                            • Surfing through scenes
                          • Chapter 6:
                            • Menu design
                          • Chapter 7:
                          • Implementing particle systems
                          • Chapter 8:
                            • Familiarizing yourself with tilemaps
                          • Chapter 9:
                            • Playing sounds with CocosDenshion
                          • Chapter 10:
                            • Using physics engine
                          • Chapter 11:
                            • Integrating OpenFeint

                          Pablo Ruiz

                          Pablo Ruiz started his carreer as a developer working as PHP developer for a local government office in 2007. Before that, he would work in QA for a big multinational game development company.

                          While working as a PHP developer he would build big administrative and accounting systems which were used across all the offices for their daily work.

                          In 2008 he began working on some small C# games using the XNA framework in his spare time. At the time, the iPhone was gaining ground so he began working on a personal project, a little game called Aqua Rush. After releasing it and starting doing consultancy work for several companies he left his day job and began working as a freelance iPhone developer.

                          Half a year later, he founded, with his partner, their own company; Infinix Mobile Software Development in Argentina, where he employs and trains students to learn and master the art of programming.

                          Code Downloads

                          Download the code and support files for this book.


                          Submit Errata

                          Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


                          Errata

                          - 2 submitted: last submission 06 Nov 2012

                          Errata type: Code | Page numbers: 153

                          The line :
                          isTouchEnabled = YES;
                          should read : self.isTouchEnabled = YES;
                          otherwise the CCLayer property isn't recognised by the complier.

                          Errata type: Spelling Error | Page numbers: 26

                          -(id) removeAllChildernWithCleanup:(BOOL)cleanup

                          Should read:

                          -(id) removeAllChildrenWithCleanup:(BOOL)cleanup

                          Errata type: Code | Page numbers: 189

                          [theGame loseLive];

                          should be

                          [theGame loseLife];

                          Errata type: Code | Page numbers: 60

                          [grid[i][j-1].mySprite setPosition:ccp(42*i + GRID_OFFSET.x,42*(j-1) GRID_OFFSET.y)];

                          should be

                          [grid[i][j-1].mySprite setPosition:ccp(42*i + GRID_OFFSET.x,42*(j-1) + GRID_OFFSET.y)];


                          and don't forget to mention to add

                          -(CGRect)rect;
                          to Stone.h, so it builds.

                          Errata type: Code | Page numbers: 203

                          Missing the line in the HudLayer class init method to enable touches.

                          self.isTouchEnabled=YES;

                          Errata type: Code | Page numbers: 14

                          Time for action-installing the templates

                          The step 2. command should read:

                          cd desktop/Cocos2d
                          ./install-templates.sh

                           Errata type: Code | Page numbers: 173

                          The fire method is missing the line:

                          [self.mySprite setVisible:YES];

                          This enables the bullet to be seen when fired.

                          Errata type: Code | Page numbers: 173

                          3. Add a new property to the GameLayer, NSMutableArray * enemies. This array will hold the bullets.

                          Should be NSMutableArray * bullets

                           

                          Errata type: Code | Page numbers: 48

                          code says
                          [self addChild:mySprite z:1];

                          but explanation says: "...stone object with a z-order of two"
                          so code should really be
                          [self addChild:mySprite z:2];

                          Errata type: Code (Typo) | Page number: 82 | Errata date: 20 May 11

                          CCSpriteBatchNode * s = (CCSpriteBatchNode *)[theGame getChildByTag:K_SSheet];
                          Should be
                          CCSpriteBatchNode * s = (CCSpriteBatchNode *)[theGame getChildByTag:kSSheet];

                          Errata type: Code (Typo) | Page number: 56 | Errata date: 24 May, 12

                          The line  return CGRectContainsPoint( self.rect , ....... )

                          Should be

                          return CGRectContainsPoint( [self rect] , .......)

                          Errata type: Code | Page numbers: 94

                          code says....
                          if(nilCount >0 && !d.disappearing) {
                          [d.mySprite runAction:[CCMoveTo actionWithDuration: (0.5 * nilCount)/3 position:ccp(42*i + GRID_OFFSET.x,42* (j-nilCount) + GRID_OFFSET.y)]];
                          }

                          should be:


                          if(nilCount >0 && !d.disappearing) {
                          [stone.mySprite runAction:[CCMoveTo actionWithDuration: (0.5 * nilCount)/3 position:ccp(42*i + GRID_OFFSET.x,42* (j-nilCount) + GRID_OFFSET.y)]];
                          }

                          Errata type: Code | Page numbers: 82

                          code says:
                          CCSpriteBatchNode * s = (CCSpriteBatchNode *)[theGame getChildByTag:K_SSheet];

                          should be
                          CCSpriteBatchNode * s = (CCSpriteBatchNode *)[theGame getChildByTag:kSSheet];

                          Sample chapters

                          You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

                          Frequently bought together

                          Cocos2d for iPhone 0.99 Beginner's Guide +    Creating Games with cocos2d for iPhone 2 =
                          50% Off
                          the second eBook
                          Price for both: £21.95

                          Buy both these recommended eBooks together and get 50% off the cheapest eBook.

                          What you will learn from this book

                          • Learn the basics of the most popular 2D framework for iPhone
                          • Packed with tips and tricks for using this framework
                          • Use actions and effects to make your graphics stand out
                          • Implement particles to make your players vibrate
                          • Make huge levels with Tilemaps
                          • Play sounds in many different ways
                          • Give your game real-life physics
                          • Integrate OpenFeint, the most popular social gaming network, with your game

                          In Detail

                          Cocos2d for iPhone is a robust but simple-to-use 2D game framework for iPhone. If you are just starting with game programming, cocos2d will enable you to make your first game in no time. Even if you are a seasoned game developer, you will still be able to benefit from what it offers. Yet beginning with cocos2d for iPhone may be an arduous task without a proper guide.

                          Cocos2d for iPhone 0.99 Beginner’s Guide will help you to learn how to make games with cocos2d from the ground up. You will learn all the key concepts of the framework and game programming in general while building your first game using this exciting platform.

                          You will start by learning the basics of cocos2d then you will learn how to enhance your game with a lot of cool features and eye candy. After spending a little time learning the basics, you will jump straight into action. The book will then teach you to build games from scratch and how to add animations, sounds, and particle effects to them. Then you will be guided to have your game behave as in real life by using a physics engine. After reading Cocos2d for iPhone 0.99 Beginner's Guide, you will be able to write your own games for iPhone while using all the elements Pros use. There are a lot of examples, images, and diagrams to get you up to speed in no time.

                          This book is a practical guide for building your own fun and exciting iPhone games in no time using the cocos2d for iPhone framework.

                          Approach

                          This is a beginner's guide.

                          Who this book is for

                          If you want to get into the iPhone industry and have your games compete with the best, this book is for you. You should have some basic programming experience with Objective-C and a good understanding of OOP. A little experience of game programming in any language is welcome but not a must.

                          Code Download and Errata
                          Packt Anytime, Anywhere
                          Register Books
                          Print Upgrades
                          eBook Downloads
                          Video Support
                          Contact Us
                          Awards Voting Nominations Previous Winners
                          Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
                          Resources
                          Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software