Kirill Muzykov

Forum Replies Created

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • in reply to: Chapter 12 #334
    Kirill Muzykov
    Keymaster

    No worries! As I’ve mentioned, I rarely read Preface too, since I want to get straight to action! ๐Ÿ™‚

    in reply to: FAQ: Please Read this First #328
    Kirill Muzykov
    Keymaster

    Here are some of the Frequently Asked Questions about the book:

    1. Where can I get Chapter 12?

    First of all here is the link:
    https://www.packtpub.com/sites/default/files/downloads/0144OS_Chapter_12.pdf

    Unfortunately, there was a page limit for this book. Otherwise it would fall into a different printing category, with a different price and so on. So instead we decided to make Chapter 12 (which is quite big) as a separate downloadable chapter. Good news, is that the book price stayed the same and I had no limitation on adding screenshots in this chapter!

    The link to download Chapter 12 is given in Preface of th ebook, but I guess some people missed it, so I decided to add this information to FAQ.

    2. CCSpriteBatchNode is Deprecated

    It means that you’re using a newer version of Cocos2D-Swift (e.g. v3.2). I would recommend getting Cocos2D v3.0 and use it while you’re completing the code from the book.

    After you finish the book it will be very easy to switch to the newest version of Cocos2D, but when you’re only learning it is quite hard to keep even those minor differences in mind. Believe my experience, I’ve been switching to the newer Cocos2D versions starting from v0.99 and never had any issues that couldn’t be solved by reviewing “What’s new” section or googling for 2 minutes. And there were a lot more significant changes than those from v3.0 to v3.2.

    But why CCSpriteBatchNode is deprecated?
    In cocos2d v3.2 you donโ€™t have to add sprites from the spritesheet to a CCSpriteBatchNode for batching to work. Sprites are batched automatically when they share a texture, blending mode and shader settings.

    It means you can just add sprites to the scene directly or replace the CCSpriteBatchNode with a simple CCNode in case you still want to keep the hierarchy.

    If you want to know more you can read the following thread on Cocos2D forum:
    http://forum.cocos2d-swift.org/t/ccspritebatchnode-is-deprecated-in-v3-1/14216/6

    3. I found a bug, typo,…

    Well, that’s sad ๐Ÿ™ We really tried to create a perfect book. However, if you did find a bug please check if it wasn’t reporter and fixed earlier using this link:
    https://www.packtpub.com/books/content/support/16966

    If you can’t find it there please create a topic on this forum. Thank you!

    in reply to: Chapter 12 #327
    Kirill Muzykov
    Keymaster

    Hi Jaime,

    The link to download Chapter 12 is in the Preface, but I guess none reads Preface. To be honest I rarely read it myself ๐Ÿ™‚

    Here is a link to download Chapter 12:
    https://www.packtpub.com/sites/default/files/downloads/0144OS_Chapter_12.pdf

    in reply to: CCSpriteBatchNode is Deprecated #325
    Kirill Muzykov
    Keymaster

    Hi, sorry for late reply. Glad that you’ve managed to solve your issue!

    in reply to: CCSpriteBatchNode is Deprecated #321
    Kirill Muzykov
    Keymaster

    In cocos2d v3.2 you don’t have to add sprites from the spritesheet to a CCSpriteBatchNode for batching to work.

    Sprites are batched automatically when they share a texture, blending mode and shader settings.

    So you can just add them to the scene directly or replace the CCSpriteBatchNode with a simple CCNode in case you still want to keep the hierarchy.

    You can find more information in this thread:
    http://forum.cocos2d-swift.org/t/ccspritebatchnode-is-deprecated-in-v3-1/14216/6

    However, I would advise you to complete the book using cocos2d v3.0 and then learn few improvements introduced in v3.1 and v3.2. It will be very easy to modify your code to v3.2 when you know all the basics, but it can be quite hard to keep even minor differences in your head while you still learning.

    Kirill Muzykov
    Keymaster

    Hi,

    Yes. This is a sad typo made at the stage when the book was laid out for PDF. Final drafts that I sent had the correct version.

    Please check the Support tab on the book’s official page for errata related fixes.

    Regarding this exact typo:

    The following 6th bullet point:

    In the GameScene.m file, add the createBatchNode method as follows:

    -(void)addBird 
    { 
           CGSize viewSize = [CCDirector sharedDirector].viewSize; 
           _bird = [[Bird alloc] 
                      initWithBirdType:BirdTypeSmall]; 
           _bird.position = ccp(viewSize.width * 0.5f, 
                                       viewSize.height * 0.9f); 
           [_batchNode addChild:_bird]; 
    }

    Should be:

    In the GameScene.m file, add the createBatchNode method as follows:

    -(void)createBatchNode
    {
         //1
         [[CCSpriteFrameCache sharedSpriteFrameCache]
         addSpriteFramesWithFile:@"Cocohunt.plist"];
    
         //2
         _batchNode = [CCSpriteBatchNode 
                             batchNodeWithFile:@"Cocohunt.png"];
         //3
         [self addChild:_batchNode z:1];
    }
    in reply to: How to debug signal SIGABRT #293
    Kirill Muzykov
    Keymaster

    Hi,

    First of all, the answer to the question on how to debug errors like this. There is a nice tutorial by Matthijs Hollemans on RayWenderlich.com on debugging iOS apps:
    http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1
    http://www.raywenderlich.com/10505/my-app-crashed-now-what-part-2

    I strongly advise to read it, since it will save you many hours in the future. However, few most important things to do right now is:

    1. Add “All exceptions” breakpoint.
    Right now you only see exception on its final stop on the way out. To see the exact line causing this exception you need to add “All Exceptions” breakpoint, that will stop execution right when your game is only going to throw an exception.

    adding all exceptions breakpoint

    2. Decompress the thread list
    By default Xcode compresses the stack trace of exception, removing intermediate function calls, which Xcode finds unimportant. However, they can be important to developers. So it is always better to make sure you see the full stack.

    Seeing full stack trace in Xcode

    3. Find the place in your code causing the exception.
    High chances that the code that you wrote yourself is not throwing an exception. In most cases it is thrown by some internal function of cocos2d which you call indirectly.

    Here is an example:

    I’ve modified the code to cause an exception (passing nil as image name). This is what you will see when Xcode will stop (because of “All Exceptions” breakpoint).

    finding place in your code caused the exception

    As you can see Xcode shows the line that throws the exception and full stack trace. However, this line is not in your code. The line that throws exception is an internal line of Cocos2D that checks that the image name must be non nil.

    There is only a small portion of your code in the stack trace (marked in green). So to see the line of your code that causing the exception you should check methods in the stack trace that you wrote. Since there is a very low chance that the error is in iOS system code or Cocos2D code (marked in Red).

    To do this. You select the last of your methods executed before the exception. Most likely the code causing the exception is in this method. I say most likely, because, maybe, you’ve passed incorrect parameter to your method which just passed it to Cocos2D, so you should fix the original caller method instead.

    Now you can see the line in the code you wrote that causes the exception. In this case I’ve intentionally passed nil as image name to get the exception.

    4. Pay attention to console output.
    Cocos2D logs errors and warnings in the console. So even if you don’t get the exception you might see a warning that some image was not found or other warnings.

    5. Compare you code with the one that comes with the book
    If you just can’t find the code causing the error you might compare your code with the code that comes with the book. When learning programming and can’t find where the bug is I’ve used following technique.

    I’ve replaced my code with the code from the book, but saved my code somewhere. Then I checked that everything works and replaced the working code method by method with my code until I get the error. When I get it I’ve compared methods line by line or even symbol by symbol and found what causing errors.

    If the method is big I might even replaced half of the method with my code, checked and then replaced the other half, or even line by line (actually did this once, and found that the error was I’ve put Russian “o” instead of English “o” in the file name and that caused error which I wasn’t able to find by only reviewing the code).

    Hope it helps you to find your bug!

Viewing 7 posts - 1 through 7 (of 7 total)