Game Development Reference
In-Depth Information
the equality operator == in conditions. The brackets ensure that the assignment occurs
first, and only afterward is the result ( button ) used as the condition—which is true as
long as button is not nil .
Of note is the @(count).stringValue literal. In modern Objective-C, you can ini-
tialize arrays, dictionaries, and numbers using the literal syntax.
NSArray* array = @[obj1, obj2, obj3];
NSDictionary* dict = @{key1: obj1, key2: obj2, key3: obj3};
NSNumber* number = @(1234);
NSNumber* number = @(YES);
NSNumber* number = @(count);
The literal syntax is easier to read and shorter than using the regular initializers for the
preceding classes. The expression @(count) thus takes the count value and returns an
NSNumber object. The NSNumber class conveniently creates a string representation of
its value via the stringValue property. Therefore, @(count).stringValue is
shorthand for converting a number to a NSString object, turning a 1 into @"1" . This
string can then be compared with the names of the buttons, which should have 1 through 9
as their name string.
Note Why not use a NSNumber to begin with? That's simple: NSNumber is
an immutable class. You have to create a new NSNumber object if the value
must change. There is no corresponding NSMutableNumber class, either.
The counterpart, string-to-number conversion, happens in button.name.intValue .
The button.name is an NSString object, and NSString has several convenience
properties like intValue , which attempt to convert the string to an int value.
However, if that fails—for instance, if you used the string @"one" —the property will
simply return 0 .
The button's parent node is a CCSprite —one of the W#_l# sprites. If the button's level
is accessible, the sprite gets the whiteColor assigned, which removes any tinting.
CCColor is the color class used by Cocos2D; it is very similar to UIColor and NSCo-
lor .
Search WWH ::




Custom Search