Game Development Reference
In-Depth Information
Interface Builder will automatically instantiate the CCGLView for you. You only need
to attach the CCDirector with this particular view. The On/Off Switch should serve as
the toggle button that turns the cocos2d view on and off.
First, some preparations. Select the CCGLView view and switch to the Attributes In-
spector (View Utilities Attributes Inspector). Check the Hidden check box so
that the view is initially hidden. With the Attributes Inspector still open, select the On/
Off Switch and change its initial State to Off. You'll hide and unhide the CCGLView
Note The cocos2d CCDirector class can manage only one CCGLView at a
time, mainly because the CCDirector class is a singleton. An app using mul-
tiple cocos2d views at the same time is not currently possible without signific-
ant changes to cocos2d. Support for multiple cocos2d views is on the develop-
ment roadmap.
Now you need to make the connection from the buttons on the view to the ViewCon-
troller class. The easiest way to do so is to open an Assistant Editor in Xcode 4 via
View Editor Assistant. You can customize the layout of the Assistant Editor
with one of the selections available under View Assistant Editor. The Assistant Ed-
itor will automatically display the ViewController.h file.
In the Interface Builder view, select the On/Off Switch and right-click it. It doesn't
matter if you select it from the list or click its view. The context menu that opens shows
a list of events that the control sends. Click the circle next to the Value Changed event
and drag it over to the Assistant Editor. You'll notice that it will highlight a line with
the label Insert Action if you drag it somewhere below the class @interface brack-
ets and above the @end statement. That's where you should drop the arrow to make the
connection. A pop-up view will show up and ask you for the name of the event. I de-
cided to call mine switchChanged . You can leave all the other settings at their de-
fault values and then make the connection by clicking the Connect button in the pop-up
Interface Builder has automatically created the necessary code for you in order to re-
ceive the particular event that you just connected. There's new code both in the inter-
face and implementation sections of the ViewController class. Before you review
Search Nedrilad ::

Custom Search