Game Development Reference
In-Depth Information
{
trans = [CCTransitionSlideInL transitionWithDuration:1 scene:newScene];
}
else if (selection == 1)
{
trans = [CCTransitionShrinkGrow transitionWithDuration:1 scene:newScene];
}
else
{
trans = [CCTransitionSlideInR transitionWithDuration:1 scene:newScene];
}
[director replaceScene:trans];
}
}
Because the user can press the Segmented Control buttons at any time, even before the
cocos2d view is initialized, the first thing this method does is to check that the dir-
ector.view exists and is not hidden. Otherwise, the remaining code could crash the
app.
The sender parameter is always the control that triggered the event. Here I rightfully
assume that it's a UISegmentedControl . If you ever change the control, you have
to change the control's class here as well. Via the selectedSegmentIndex , you
get the index of the currently selected button, which is then used to decide which trans-
ition to use for the new scene. I'm simply creating a new instance of the same Hel-
loWorldLayer class; of course, you can also use different scene classes for each
button if you want. At last, trans is used with the director method replaceS-
cene to actually change the scene to the new one using a transition.
Note The cocos2d transitions will act only on the cocos2d view and its nodes.
UIKit views will be unaffected by the cocos2d transitions. But you can use
UIView animations and transitions on the cocos2d view. You can learn more
about UIView animations here: http://developer.apple.com/lib-
rary/ios/#documentation/WindowsViews/Conceptual/
ViewPG_iPhoneOS/AnimatingViews/AnimatingViews.html .
Search Nedrilad ::




Custom Search