Rqgg Page 1/2

quidnuncoceanMobile - Wireless

Dec 10, 2013 (3 years and 8 months ago)

123 views

Restart Current scene in cocos2d
Asked by
YeahShad
on 2013-04-14T20:22:40-04:00
I am wondering what is the proper way to restart the current scene in cocos2d since I can´t get it
working properly. I am using the following code to restart the actual scene, but only a black screen
appears....


CCScene *currentScene = [CCDirector sharedDirector].runningScene; CCScene *newScene =
[[[currentScene class] alloc] init]; [[CCDirector sharedDirector] replaceScene:[CCTransitionFade
transitionWithDuration:0.7f scene:newScene]];
Note: I don´t know if this has something to do with
the fact (I guess not) that this code is run from a CClayer subclass that is in charge of managing the
pause menus and stuff.

Thanks!!

Best Answer
Answer by
Ssantos
on 2013-04-14T21:09:23-04:00
I suppose it has something to do with that manual alloc. In most cases, it's better to call cocos2d
static constructors, and let it handle the memory management for you. This is what I do.-


MyClassScene *newScene = [MyClassScene node]; [[CCDirector sharedDirector]
replaceScene:[CCTransitionFade transitionWithDuration:kTransitionTime scene:newScene
withColor:ccc3(255, 255, 255)]];
Hope it helps.

Archives
Technology
Programmers
Apr 14th, 2013
Week 15, 2013
April, 2013
Related
ccTouchBegan doesnt work-iOS
Boundary for sprites in cocos2d?
IOS, ARC, Property: (readwrite, nonatomic) vs (radwrite, retain, nonatomic)
What is the best way to draw a large number of lines using openGL and cocos2D?
The best practice for retrieving level editor data from an ios device
IOS Game - Life Regeneration
Box2d and Cocos2d with faked 3d view
Cocos2d-x and CocosBuilder multi-resolution for ios and android
How to stop runAction in cocos2d
sprite sheets in native app (NOT cocos2d)
View Online
Rqgg
Page 1/2
Restart Current scene in cocos2d
http://www.rqgg.net/topic/munkn-restart-current-scene-in-cocos2d.html
Rqgg
Page 2/2