Game Development Reference
In-Depth Information
should do so now by selecting Edit Refactor Convert to Objective-C ARC …
from Xcode's menu. Make sure only the ScrollingWithJoy03 project is selected before
running the ARC conversion check. When Xcode is done checking you'll see a pre-
view; click Save to accept all changes.
Tip If you ever run into third-party code that can't be refactored to ARC, you
can do one of two things. One is to compile that code as a separate static library
with ARC disabled and linking that library with your app, just like what you
did with cocos2d in Chapter 2 . The alternative is to add the compiler flag
-fobjc-no-arc to every file that should be compiled without ARC. To add
the flag, in the target's Build Phases tab expand the Compile Sources section
and enter the flag on the right-hand side to the Compiler Flags column. Note
that code requiring either of these approaches may be generally incompatible
with ARC. Consult with the author or other users of the code to find out wheth-
er the code is safe to use with ARC.
Now the code will compile but not without four warnings complaining about
sharedDispatcher being deprecated. You can choose to ignore the warnings but
eventually you're going to have to fix them, so you may as well do it now. The lines in
question all start with [CCTouchDispatcher sharedDispatcher] , for ex-
[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
To fix the warning, change the lines so that they use the touch dispatcher provided by
CCDirector instead:
[ [CCDirector sharedDirector].touchDispatcher removeDelegate:self];
Touch Button to Shoot
Let's try this. With the SneakyInput source code added to the project
ScrollingWithJoy03 , the first goal is to add a button that allows the player to
shoot bullets from the player's ship. You're going to add a separate InputLayer
class to the project by adding an Objective-C class template file and making sure it's
derived from CCLayer. Add the InputLayer class instance to the GameLayer
Search Nedrilad ::

Custom Search