Advertisement
Guest User

Cocos2D for Beginners Errata

a guest
Jan 18th, 2011
1,564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.38 KB | None | 0 0
  1. Cocos2D for Beginners Errata
  2. ============================
  3.  
  4. Submitted Count : 17
  5.  
  6. Page 22 *
  7.  
  8. Example HelloWorldScene class differs, if using the latest release, 0.99.5
  9.  
  10.  
  11. Page 28 *
  12.  
  13. The book uses the schedule:@selector method of scheduling an update to the node. However, the cocos wiki says to use scheduleUpdate over scheduleSelector for performance reasons : http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:draw_update#scheduleupdate
  14.  
  15. Page 42 *
  16.  
  17. Example code provided in point 2 at the top of the page does not match that explained in the 'What just happened?' section at the bottom of the page. One uses absolute positioning, whereas the other uses a dynamic positioning, based on the size of the window.
  18.  
  19. Page 47 *
  20.  
  21. The code discussed in 'What just happened?' refers to constant STONE_TYPES, which has not been defined anywhere in the previous code. On page 46, the number 4 is used directly with the arc4random function.
  22.  
  23. Page 49 *
  24.  
  25. The line in the GameScene.h listing in section 1 should read :
  26.  
  27. +(CCScene *) scene;
  28.  
  29. not :
  30.  
  31. +(CCScene) scene;
  32.  
  33. The example code returns a compiler error.
  34.  
  35. Page 51 *
  36.  
  37. Executing the entered code crashes the application, due to the program requiring four sprite graphics for the stones : sBlue.png, sRed.png, sYellow.png and sGreen.png. These are not present in the support files for Chapter 2 when downloaded from the Packt site, only a combined spritesheet image. Also, none of the stones in the example share the colours listed, they are different.
  38.  
  39. In the 'What just happened?' section, the location of the gridBackground is specified as :
  40.  
  41. [gridBackground setPosition:ccp(305,160)];
  42.  
  43. as opposed to the original listing on page 49, which reads :
  44.  
  45. [gridBackground setPosition:ccp(305,154)];
  46.  
  47. The original positioning leaves the grid misaligned with the stones.
  48.  
  49.  
  50. Page 56 *
  51.  
  52. The code for the rect function has to be placed before the containsTouchLocation function, otherwise, it will not be able to reference it.
  53. Likewise, the code for the containsTouchLocation function has to be placed before the ccTouchBegan function, otherwise, it too will have referential issues.
  54.  
  55.  
  56. Page 57 *
  57.  
  58. The line that checks the state of theGame.allowTouch fails, as the property hasn't been synthesized as part of the implementation.
  59.  
  60. Page 66 *
  61.  
  62. There is additional code for incrementing the game score in the 'What just happened?' code that is not included in the checkGroups: listing on page 64.
  63.  
  64. Page 71 *
  65.  
  66. The following line :
  67.  
  68. CGRect color = [stone setStoneColor:stoneT];
  69.  
  70. gives an error at compilation, as it expects a CGRect to be returned from the setStoneColor: method of the Stone class. However, as at this point, all of the stones are using individual sprite files, the method returns an NSString with the filename of the sprite that needs to be loaded to replace the stone. This code will only work with the spritesheet approach to loading sprites, which is not discussed or implemented until page 79.
  71.  
  72. The correct code can be found at the top of page 77.
  73.  
  74. Page 74 *
  75.  
  76. remainingTime has not been added to the interface definition for the GameLayer, so can't be set to MAX_TIME.
  77. bar has also not been added to the same interface definition, so is also not able to be set.
  78. The bar logic references bar.png, which the reader isn't instructed to add to their resources folder.
  79.  
  80. Page 77
  81.  
  82. sSmile.png is not included in the downloadable source code.
  83.  
  84. Page 82 *
  85.  
  86. When changing the return type of the setStoneColor method, this also needs to be set in the header file.
  87.  
  88. Page 103 *
  89.  
  90. The code shown to load the grid background by using the spritesheet and the getChildByTag with the constant K_GBACK haven't been run through in previous chapters.
  91. This is present in the example project for chapter 3, however.
  92.  
  93. Page 104 *
  94.  
  95. With 0.99.5, CCRepeat no longer accepts CCAction as a passed type, it must be CCFiniteTimeAction, so act must be defined as such.
  96.  
  97. Page 111 *
  98.  
  99. Step 3 in the Time for Action section refers to a variable called disallowTouch that needs to be set to YES to stop the player interacting with the stones. The actual instance variable built into the code so far is called allowTouch, so this needs to be set to NO.
  100.  
  101.  
  102. Page 118
  103.  
  104. The reader is prompted to include stonesSheet.png and stonesSheet.plist from the source files, but these are not included in the files.
  105. In section 2, the code added to the init method refers to a file called 'colouredSheet.plist', which also accesses a file called 'colouredSheet.png', both of which are included in the source files.
  106.  
  107. Page 153
  108.  
  109. The line :
  110.  
  111. isTouchEnabled = YES;
  112.  
  113. should read :
  114.  
  115. self.isTouchEnabled = YES;
  116.  
  117. otherwise the CCLayer property isn't recognised by the complier.
  118.  
  119. The line that sets the image position has the X and Y co-ordinates transposed :
  120.  
  121. [splashImage setPosition:ccp(240,160)];
  122.  
  123. should read :
  124.  
  125. [splashImage setPosition:ccp(160,240)];
  126.  
  127. Page 158
  128.  
  129. The CCFadeTransition has been replaced with CCTransitionFade in 0.99.5
  130.  
  131. Chapter 2 General
  132. From looking at the cocos2d source code included with the ColouredStones Final project, it is based on the 0.99.5 template. However, the ColouredStonesAppDelegate.m file has deprecated functions included in it, suggesting that the code is based on an earlier template. This makes it very confusing for a beginner. More confusing to a beginner is the additional GameConfig.h and RootViewController files included with the 0.99.5 template.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement