Game Development Reference
In-Depth Information
Listing 14-1
.
NSLog used to log when Scroll View delegate methods run
-(void) scrollViewDidEndDragging:(CCScrollView *)scrollView
willDecelerate:(BOOL)decelerate
{
NSLog(@"%@%@", NSStringFromSelector(_cmd), decelerate
? @"YES" : @"NO");
}
Together with the other delegate method's logging,
NSLog
will print a series of strings to
the Xcode debug console, as seen in
Figure 14-1
, when you interact with the
Scroll View
.
Figure 14-1
.
NSLog output in Xcode's debug console after interacting with the level-selection Scroll View
This series of log statements instantly visualizes the flow of execution. You can clearly
see that
scrollViewWillBeginDragging:
is the first delegate method called,
while
scrollViewDidEndDragging
with decelerate enabled causes the
Scroll View
to continue scrolling past the point where the user stopped dragging. The
Scroll View
does
so to move the nearest page to its designated position. Once the page has been moved to
its position, the scrolling ends with
scrollViewDidEndDecelerating
.
Logging is particularly useful if you need to monitor the change of values over timeāfor
instance, logging the position of a node and its distance to another node in the update
method.
Caution
Printing a log line to the console takes time, and printing a long string
with many format specifiers and variables will take longer than a short string. If
you call
NSLog
once every frame, it may already be enough to show a notice-
able slowdown. So don't forget to remove or comment the
NSLog
statements
after they've done their job.
Search WWH ::
Custom Search