Game Development Reference
In-Depth Information
ally member functions, during this chapter I will still refer to them as such because
the terminology is more familiar.
The syntax for message passing in Objective-C might be a little odd for someone
used to the C++/Java language style. To call a member function in C++, one might
use the following:
myClass->myFunction(arg);
But to pass an equivalent message in Objective-C, the syntax is this instead:
[myClass myMessage: arg];
While browsing through the code, you may also notice that function declarations
have either a + or - in front of them. A + signifies the method is a class method
(which you can think of as a static function in C++), whereas a - signifies the
method is an instance method (or a regular member function). Here's an example
of each:
Click here to view code image
// Class method (essentially a static function)
+( void ) func1;
// Instance method (regular member function)
-( void ) funct2;
If you find yourself confused by the syntax of Objective-C, note that it is possible
to limit the usage of Objective-C in an iOS app. This is because it plays nicely
with C++ code, with a few restrictions. So it is absolutely possible to write 90%
of the code for an app in C++ and then only use Objective-C where it must inter-
face with the operating system. This is the recommended approach for a mobile
game that you might want to later release on the Android platform, because it will
reduce the amount of code that must be rewritten. However, because Ship Attack
uses the coco2d framework, it is written 100% in Objective-C.
cocos2d
Cocos2d (available at www.cocos2d-iphone.org ) is a 2D game framework that tar-
gets both the Mac and iOS platforms. Because it's only for these two platforms, its
interfaces are all written in Objective-C. Cocos2d provides a lot of built-in func-
tionality for 2D sprites, so it makes creating 2D games fairly painless.
Search WWH ::




Custom Search