Hi guys,
i know this was asked before but I can't seem to find it...
Does anyone knows how to have a smooth transition from the default.png image to the first scene? I always get a flicker...
Thanks!
A fast, easy to use, free, and community supported 2D game engine
Hi guys,
i know this was asked before but I can't seem to find it...
Does anyone knows how to have a smooth transition from the default.png image to the first scene? I always get a flicker...
Thanks!
//Fix flash of black before first scene can load
Sprite *sprite = [[Sprite spriteWithFile:@"Default.png"] retain];
sprite.anchorPoint = CGPointZero;
[sprite draw];
[[[Director sharedDirector] openGLView] swapBuffers];
[sprite release];Thanks CJ :)
Hi
I just browsed the forum for a solution for this, but I do not seem to get this to work for me. How and when exactly do you do that ?
This what I have at the moment :
// create an initilize the main UIWindow
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Attach cocos2d to the window
[[Director sharedDirector] attachInWindow:window];
[Director sharedDirector].displayFPS = YES;
// before creating any layer, set the landscape mode
[[Director sharedDirector] setDeviceOrientation:CCDeviceOrientationLandscapeLeft];
// Make the window visible
[window makeKeyAndVisible];
GameScene * gs = [GameScene node];
[[Director sharedDirector] runWithScene:[ZoomFlipXTransition transitionWithDuration:1.0 scene:gs]];
and the Default.png is just there for hald a second or so, which does not look very pretty.
To get rid of the flicker you put the code CJ posted after your [window makeKeyAndVisible]; line.
// Make the window visible
[window makeKeyAndVisible];
//Fix flash of black before first scene can load
Sprite *sprite = [[Sprite spriteWithFile:@"Default.png"] retain];
sprite.anchorPoint = CGPointZero;
[sprite draw];
[[[Director sharedDirector] openGLView] swapBuffers];
[sprite release];
GameScene * gs = [GameScene node];
[[Director sharedDirector] runWithScene:[ZoomFlipXTransition transitionWithDuration:1.0 scene:gs]];Hmm thats what I have. Still no change
Try not using a transition when you call runWithScene.
What decices are you guys (with flickering) using. On my Ipod Touch 2nd gen (SDK 2.2.1) I do runWithScene with a fadein transition and I see no flickering.
You can always try "hacky" way.
go to Director.m (cocos2d)
find:
animationTimer = [NSTimer scheduledTimerWithTimeInterval:animationInterval target:self selector:@selector(mainLoop) userInfo:nil repeats:YES];
before it add:
[self mainLoop];
Okay, I'm confused... CJ's fix used to work quite well in my program, but not anymore. Something must have changed, but I have no idea what. Do any of you have any idea what's going wrong here?
This is in my AppDelegate's applicationDidFinishLaunching method, just after the window is made key and visible, but just before I create the first CCScene:
//Fix flash of black before first scene can load (from http://www.cocos2d-iphone.org/forum/topic/2055)
CCSprite *sprite = [[CCSprite spriteWithFile:@"Default.png"] retain];
sprite.anchorPoint = CGPointZero;
[sprite draw];
[[[CCDirector sharedDirector] openGLView] swapBuffers];
[sprite release];For latest versions of cocos:
CCSprite *sprite = [CCSprite spriteWithFile:@"Default.png"];
sprite.anchorPoint = CGPointZero;
CC_ENABLE_DEFAULT_GL_STATES();
[sprite draw];
CC_DISABLE_DEFAULT_GL_STATES();
[[[CCDirector sharedDirector] openGLView] swapBuffers];Thanks!!
So CCSprites don't need retain/release anymore, and a sprite won't "draw" unless the GLstate is set back to the defaults.
Looks like I need to pay more attention to those release notes...
Thanks again!
"So CCSprites don't need retain/release anymore" - they never did. They didnt do any harm in your original code, but werent necessary.
Update:
Since Apple is allowing the undocumented API call to UIGetScreenImage()
I've updated my code for re-displaying the default screen so that when supported it will not need to read from the file system, and instead just redisplay the contents of the screen directly.
This is needed to call the private API method:
extern "C" CGImageRef UIGetScreenImage(void);
inline CGImageRef CreateCGImageWithContentsOfScreen(void) {
return UIGetScreenImage(); /* already retained, so be sure to do a CGImageRelease() on the returned image later. */
}
After attaching the director but before running the first scene do:
CCDirector *director = [CCDirector sharedDirector];
NSString *defaultFile = @"Default.png";
CCSprite *defSprite;
CGImageRef defaultImage = CreateCGImageWithContentsOfScreen();
if(defaultImage){
CCLOG(@"Redisplay DefaultImage: Got Default.png image for 'free' by grabbing UI framebuffer contents.");
defSprite = [CCSprite spriteWithCGImage:defaultImage key:defaultFile];
}else{
CCLOG(@"Redisplay DefaultImage: Getting Default.png image from filesystem.");
defSprite = [CCSprite spriteWithFile:defaultFile];
}
CGImageRelease(defaultImage);
defSprite.anchorPoint = CGPointZero;
CC_ENABLE_DEFAULT_GL_STATES();
[defSprite draw];
CC_DISABLE_DEFAULT_GL_STATES();
[[director openGLView] swapBuffers];
[[CCTextureCache sharedTextureCache] removeTexture:[defSprite texture]];@CJ: nice.
would you like to update the "director flicker tip" with your tip ?
http://www.cocos2d-iphone.org/wiki/doku.php/tips:director_flicker
Thanks.
@riq: I updated the wiki:
http://www.cocos2d-iphone.org/wiki/doku.php/tips:director_flicker
Please verify accuracy of the < .99 version code because I just went off memory for the API diffs and haven't actually tested that code.
@CJ: thanks. yes, the <.99 seems to be OK.
I need to resurrect this thread as it doesn't work for me. I'm using SDK 3.2 w/ a project for the iPad which supports both LandscapeLeft and LandscapeRight. For one frame, the default.png is shown, however always rotate (like in portrait mode), it looks as if at the time of displaying the sprite the director has not yet processed the correct orientation.
@CJ: Thanks for getting back, unfortunately this doesn't fix it. If applied after the call to SetDeviceOrientation, the whole game then is wrongly orientated (portrait w/ a black stripe), if applied before the call to SetDeviceOrientation, the same effect as before.
@CJ: The solution in http://www.cocos2d-iphone.org/forum/topic/5351 seems to work fine for me, is that a "clean" solution or can we improve on that?
You must log in to post.