Warning: Use of undefined constant wp_generator - assumed 'wp_generator' (this will throw an Error in a future version of PHP) in /nfs/c03/h06/mnt/47675/domains/cocos2dbook.com/html/wp-content/plugins/wp-secure-by-sitesecuritymonitorcom/wpSecureFunctions.php on line 1177
Errata – Cocos2D Book


Updated on March 7th, 2012
Learning Cocos2D Errata

Report New Errors/Findings/Issues

Learning Cocos2D book source code is here: http://www.cocos2dbook.com/cocos2d/sourcecode/


  • iTunes Link for Space Viking is:
  • http://itunes.apple.com/us/app/space-viking/id400657526?mt=8
  • Some pre-release versions of the book had the incorrect link, as Space Viking was not yet in the AppStore

Chapter 1:

  • Figure 1.5: The project name in Figure 1.5 is incorrect, it should be CCHelloWorld instead of HelloWorld. This is just the project/app name, and does not impact any of the functionality of the the example, but subsequent figures show the project being named CCHelloWorld.
  • Text above listing 1.1: Step 2 of the “Taking HelloWorld Further” points you the reader to HelloWorldScene.m class. If you look at the source code for the book the CCHelloWorld project does contain this HelloWorldScene.m class which created a CCScene and CCLayer. If you are creating a new Cocos2D project from the Cocos2D Templates in Xcode, you will only have a class named HelloWorldLayer.m. In the case that you are following the instructions and creating your own HelloWorld sample from the Xcode Cocos2D Templates, look for the HelloWorldLayer.m class instead of HelloWorldScene.m class. Scenes and Layers are explained in detailed a bit further in the book.
  • Listing 1.2 Title: If you are using the CCHelloWorld project included from the book source, the title is correct. If you are creating your own Hello World project from the Cocos2D Templates, the title should be HelloWorldLayer.m
  • Text after listing 1.5, bullet 12: The Cocos2D HelloWorld sample contains a class HelloWorld Layer which has both a Scene and Layer. Calling the scene method creates an instance of CCScene and adds the HelloWorld CCLayer as a child to that scene. It is a shortcut to having a CCScene and CCLayer class files, causing a bit of confusion for readers starting out with Cocos2D.

Chapter 2:

  • Creating the Background Layer Section: Step one mentions selecting the “Classes” folder, but new Cocos2D Xcode projects do not come with a Classes Folder or Group. You can create the classes without the “Classes” group or before Step 1 create a new Group called Classes by: Right Click on Space Viking in Xcode, and Select New Group, and type Classes.
  • Text above listing 2.1, “change the BackgroundLayer class to inherit from CCLayer” should say “ensure that the BackgroundLayer class inherits from CCLayer”. The BackgroundLayer class should already be set to inherit from CCLayer based on Step 3 on the previous page.
  • Listing 2.2: The “// 3” comment should be on the “if (USER_INTERFACE_IDIOM()” line, as that is the line that determines if the game is running on the iPhone/iPod touch or iPad.
  • Listing 2.4, explanation number 3. The correct name for the sprite is sv_anim_1.png and not viking1.png. It should read Allocates and initializes the vikingSprite instance variable with the image sv_anim_1.png
  • Listing 2.4, explanation number 4. If you look at the listing code in 2.4, you can see that the vikingSprite position is not being set to the hard value of 130.0f but instead to a percentage of the screen height with a “screenSize.height * 0.17f”. Using percentages instead of fixed values allows Ole to retain his position no matter what the screen height is. The text about the skipping an integer to float conversion still applies, no matter if you are using a percentage or a fixed number.
  • Listing 2.7: Import statement for SpaceVikingAppDelegate.h should be singular “#import SpaceVikingAppDelegate.h”, not SpaceVikingS. There is only 1 Ole the Viking
  • Creating the Scene 1 Texture Atlas. Be sure to use the “Add Sprites” instead of the “Add Folder” in TexturePacker, so that keys for the images in the texture atlas plist does not contain the paths. In other words, go down each folder “Detrius, EnemyRobot, etc” and select all of the images inside that folder.
  • In future revisions we will include all of the images in a single folder to simplify this step.
  • The tip on page 27 for using the 3 finger swipe to switch between header and implementation files has been changed in Xcode 4.3 and Lion. Use the keyboard shortcut Control + Command + Up or Down arrow. You can see these two options in the navigate menu as Jump to Next and Previous counterparts.

Chapter 3:

  • On page 70, the Xcode shortcut to create a new group has changed Command + Option + Z + N
  • On page 71, the Xcode shortcut to create a new file has changed to Command + Z + N
  • On page 71, when you create a new header file, Xcode adds 3 lines of boiler plate code (#ifdef statements), delete and and replace them with the code in the book.
  • Listing 3.2: The code as shown in the book will work once you create and use TextureAtlases for Space Viking. To get it to work with your Space Viking project before you create Texture Atlases, change the following:
  • sv_anim_2.png should be sv_anim_0.png
  • sv_anim_3.png should be sv_anim_1.1.png
  • sv_anim_4.png should be sv_anim_1.2.png
  • Listing 3.3: The kVikingSpriteTagValue is shown as being zero. While this will work, you should normally opt for a value greater than zero, such as 10.
  • On page 74, Class and SubClass options are now on the same panel/screen in Xcode.
  • On page 76, the if (self = [super init]) line in the init method has an extra set of parentheses. They do not impact the code, but are not needed.

Chapter 4:

  • Listing 4.3: vikingBoudingBox should be renamed “vikingBoundingBox”, note the “n” after “Bou”.
  • Page 88, the reference to Listing 4.3 should be to Listing 3.3, which is where the kVikingSpriteTagValue constant is defined.
  • Text after Listing 4.11 should read: The initJoystick method remains unchanged in functionality but is renamed initJoystickAndButtons. There are not Z values set in this method, as the joystick buttons are added last. In your games you should set the Z value of your joystick controls to be higher than anything else in your CCLayer, ensuring that the joysticks are composited on top of all other elements.

Chapter 5:

  • Text after listing 5.2. Should say “If you look closely” instead of “If look closely”, the “you” is missing.
  • Listing 5.8 – shootPhaser Method: The code for firing the phaser when the EnemyRobot is facing left is incorrect. It should say:
  • xPosition = position.x – (boundingBox.size.width * 0.542f); // Reverse by changing positive sign to negative
  • Listing 5.16: There should be an additional lines to flip the PhaserBullet when it is traveling to the right, as the animation frames are designed for a phaser traveling to the left. Add the following lines after the [phaserBullet setCharacterState:…]
  • if (phaserDirection == kDirectionRight) {
  • [phaserBullet setFlipX:YES];
  • }

Chapter 6:

  • Text after listing 6.4. There are two lines that should be added to the EnemyRobot dealloc method. The text in the book only mentions the “myDebugLabel = nil” line, as does the source code. The missing line above “myDebugLabel = nil” is “[myDebugLabel removeFromParentAndCleanup:YES]”.
  • Listing the Available Fonts in iOS Section. The code presented will output to the console a list of all the font families and fonts present on your iOS device. As mentioned in the book, the code is from Jonathan Saggau and the complete source is available at: http://www.jonathansaggau.com/blog/note_to_self/cocoa/

Chapter 7:

  • Listing 7.4: The contents of Listing 7.4 (runSceneWithID) should be pasted BELOW the init method in GameManager, not “into” the init method.
  • Listing 7.5: The contents of Listing 7.5 (openSiteWithLinkType) should be pasted BELOW the runSceneWithIDMethod in GameManager, not “into” runSceneWithID
  • Listing 7.12: playScene3Label should read: “CCLabelBMFont labelWithString:@”Mad Dreams of the Dead!” and not “Descent into Hades”
  • Listing 7.12 (towards the end): The “*backButtonLabel” initialization line is repeated. There should only be one line to initialize the back button with a label of @”Back”

Chapter 8:

  • Listing 8.4: The declaration for currentScene variable is missing. Add it immediately following hasPlayerDied variable:
  • SceneTypes currentScene;
  • Note that some of the early versions of the book do contain the missing SceneTypes declaration in Listing 8.4, and the book source code also contains the missing line.
  • Text above Listing 8.6: Should read “Add the three lines” instead of “Add the two lines”
  • Listing 8.9: NSLog statements (“Before” and “after”) should be removed or changed to CCLOG. They were incorrectly included from an earlier version of code.
  • Listing 8.9: The default case should have a “break;” line following the NSException. It works without it since the default is the last option, but it should be included for correctness.
  • Listing 8.11: There is a missing “}” before -(void)stopSoundEffect method. This closing bracket is needed for the playBackgroundTrack method
  • Text above Listing 8.14: The Adding Audio paragraph incorrectly mentions a call to soundEngineLink. This is incorrect, the call has been replaced by the macro PLAYSOUNDEFFECT(..) that you can see in code listing 8.14 and in the source code. The PLAYSOUNDEFFECT(…) macro is defined in Constants.h file.
  • Text above Listing 8.15: The contents of listing 8.15 should be copied ABOVE the init method and not in it. The playSpaceCargoShipSound is an independent method.
  • Listing 8.19: On kStateSpawning there is a snippet of code which is incorrect, the “[soundEngineLink” before PLAYSOUNDEFFECT(…) is incorrect and should not be there. The line following “case kStateSpawning:” should be “PLAYSOUNDEFFECT(ENEMYROBOT_TELEPORT);”.
  • Text after listing 8.19: The changeState method stops the walking sound by calling “STOPSOUNDEFFECT(walkingSound)” instead of the “[soundEngineLink stopEffect…”. The source code contains the correct changeState implementation.
  • Above Listing 8.20: The text of Listing 8.20 should be copied above the changeState method not into it.
  • Above Listing 8.21: Add the contents below playJumpingSound not into it.
  • Listing 8.23: When the Viking walking sound is played the audio identifier should be stored. Instead of PLAYSOUNDEFFECT(VIKING_WALKING_1) it should read:

Chapter 9:

  • Text below Figure 9.13: It says to save the Tiled files as Level2TimeMap.tmx when it should say Level2TileMap.tmx (Tile instead of Time)

Chapter 10:

  • None at this time.

Chapter 11:

  • None at this time.

Chapter 12:

  • The texture atlases for Chapter 12 are missing the Digger Enemy wheels image, digger_wheel.png
  • Figure 12.5: Shows Ole upright, when at this point in the game, he will be limp and falling through the cart. By the end of the chapter the code is in place to make this Figure possible, and have Ole upright inside the mine cart.

Chapter 13:

  • None at this time.

Chapter 14:

  • None at this time.

Chapter 15:

  • None at this time.

Chapter 16:

  • None at this time.

Report New Errors/Findings/Issues