Game Development Reference
In-Depth Information
goes wrong if you use the Step Over, Into, and Out commands to follow the program exe-
cution to see which path it takes through the Cocos2D sources.
For instance, maybe Cocos2D is simply not able to find the file you're trying to load, and
you can see that because it will not step into the if block with the fileExist-
sAtPath: condition. And since there's an NSString variable in scope, you'll see in
the Variables View what the actual path is, in case it has been modified by Cocos2D.
Given time and experience, you'll learn to assess such situations intuitively and hunt
down the most likely cause more quickly. It's a good idea to set a breakpoint and inspect
variables as soon as you run into an unexpected problem. Visually, seeing what the state
of variables is and what your code does when you run it line by line will make the major-
ity of issues rather obvious.
Sometimes, even with the debugging tools at hand, you may fail to find a particular prob-
lem for hours, or maybe even for days. If you can't find the cause within an hour and
think you have tried everything within your power to understand the problem, don't hesit-
ate to ask. Go to the SpriteBuilder ( http://forum.spritebuilder.com ) and Co-
cos2D ( http://forum.cocos2d-swift.org ) forums to ask any questions related
to them. Or go to http://stackoverflow.com to ask your programming-centric
questions. Of course, you should first narrow down the problem as much as possible and
search for all aspects of the problem you're experiencing. There's a good chance someone
else already had a similar problem, if not the same problem.
I've even heard from programmers that they were trying to fix a particular bug in their
own code for up to a week. That's just madness. You may want to make a copy of your
project and then start removing or altering possibly offending sections of code one by one
and try again until you can no longer reproduce the issue. The problem must then be re-
lated to the code you removed last. Since that is likely going to be more than one line of
code, you can use the same approach on that particular class or method until you find out
what line may be the problem. When you get close but still can't figure out the issue,
that's a good time to post that code fragment and everything you know so far on the
SpriteBuilder or Cocos2D forum.
It's also a good idea not to focus too long on fixing a particular bug. Do something else
for a while so that you can later look at the problem with a fresh set of eyes, so to speak.
Sleeping overnight on a bug and working on it the next day can do wonders. If it's a crash
or other showstopper bug, you may be able to work around it temporarily if you want to
continue doing something else within your project.
The last point before I let it go of this topic is to consider debugging as a programming
task, just like writing code. It's not a hindrance to your work but an essential, fundamental
Search WWH ::




Custom Search