Game Development Reference
In-Depth Information
Creating the UITextField should be familiar, and you also add self as a delegate
of the text field. The code that dismisses the keyboard and removes the text field when
it's empty (see Listing 15-2 ) now works for this new UITextField as well.
The next part is what cocos2d users with little or no Cocoa Touch programming experi-
ence may find odd. You can't just add a CCSprite or the sprite's texture to a
UIView . You need a UIImage class for skinning Cocoa Touch views, which you can
then comfortably create via initWithContentsOfFile . Or not? Well, the re-
turned UIImage might be nil .
It turns out that cocos2d allows you to use filenames without specifying a path because
internally it adds the path to the application's bundle file for you. This full path to a
bundle file looks something like this on an iOS device, and the path will be different
when running the app in the Simulator or on another device:
/var/mobile/Applications/...lots of letters.../CocosWithCocoa.app/background-frame.png
Because UIImage and most other Cocoa Touch classes dealing with files expect the
full path to the file, you have to use the CCFileUtils method
fullPathFromRelativePath to create an NSString , which contains the full
path to the file in the app bundle. Then you get a valid UIImage , and you can assign it
to the background property. You can see what this looks like in Figure 15-2 .
Figure 15-2 . Two UITextField views with the iPhone keyboard raised
 
 
Search Nedrilad ::




Custom Search