Game Development Reference
In-Depth Information
1. scene: SecondLayer
2. init: SecondLayer
3. onExit : FirstLayer
4. dealloc : FirstLayer
5. onEnter: SecondLayer
6. onEnterTransitionDidFinish: SecondLayer
Note that the FirstScene dealloc method is always called after the other scene
was initialized. This means that during a transition the previous scene is still in
memory until the transition has ended.
If you want to allocate memory-intensive nodes only after the previous scene is guaran-
teed to be deallocated, you have to schedule a selector to wait at least one frame before
doing the memory allocations, to be certain that the previous scene's memory is re-
leased. You can schedule a method that's guaranteed to be called during the next frame
by setting the delay parameter to 0 when scheduling the method:
[self scheduleOnce:@selector(waitOneFrame:) delay:0.0f];
The drawback to this solution is that all nodes you add after the delay will not be seen
for one frame, and during the entire transition. So it's best to save this for assets that
are initially outside the visible area or general memory allocations, such as arrays, col-
lision maps, or other game data.
Loading Next Paragraph, Please Stand By
Sooner or later you'll face noticeable loading times during scene transitions. As you
add more content, loading times correspondingly increase. As I just explained, a new
scene is allocated before the scene transition starts. If you have very complex code or
load a lot of assets in the new scene's init or onEnter methods, there will be an ob-
vious delay before the transition begins. This is especially problematic if the new scene
takes more than fractions of a second to load, and the user initiated the scene change by
clicking a button. The user may get the impression that the game has locked up or
frozen. The way to alleviate this problem is to add another scene in between: a loading
Search Nedrilad ::




Custom Search