I am testing transitions in cocos2d, and am running into a problem.
I have a MainMenu screen which contains a button. The idea is that clicking on the button will trigger a CCTransitionFadeTR transition to a WhackMain screen where there is a CCLabelTTF which displays "Hello World".
But when I press the button and start the transition, the WhackMain screen appears at full opacity for a moment before the transition from MainMenu to WhackMain begins. The transition appears to be working correctly, apart from WhackMain being visible for a moment before the transition begins.
How can I keep this from happening?
Here is my code, if it will help identify the problem:
MainMenu.m:
#import "MainMenu.h"
#import "WhackMain.h"
@implementation MainMenu
+(CCScene *) scene1 {
// 'scene' is an autorelease object.
CCScene *scene1 = [CCScene node];
// 'layer' is an autorelease object.
MainMenu *layer1 = [MainMenu node];
// add layer as a child to scene
[scene1 addChild: layer1];
// return the scene
return scene1;
}
-(id) init {
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init])) {
CGSize winSize = [[CCDirector sharedDirector] winSize];
// Create a label for display purposes
_label = [[CCLabelTTF labelWithString:@"Last button: None"
dimensions:CGSizeMake(320, 50) alignment:UITextAlignmentCenter
fontName:@"Arial" fontSize:32.0] retain];
_label.position = ccp(winSize.width/2,
winSize.height-(_label.contentSize.height/2));
[self addChild:_label];
// Standard method to create a button
CCMenuItem *starMenuItem = [CCMenuItemImage
itemFromNormalImage:@"ButtonStar.png" selectedImage:@"ButtonStarSel.png"
target:self selector:@selector(starButtonTapped:)];
// position the label on the center of the screen
starMenuItem.position = ccp( winSize.width /2 , winSize.height/2 );
CCMenu *starMenu = [CCMenu menuWithItems:starMenuItem, nil];
starMenu.position = CGPointZero;
[self addChild:starMenu];
}
return self;
}
- (void)starButtonTapped:(id)sender {
[_label setString:@"Last button: *"];
[[CCDirector sharedDirector] replaceScene:[CCTransitionFadeTR
transitionWithDuration:2 scene:[WhackMain scene2]]];
}
// on "dealloc" you need to release all your retained objects
- (void) dealloc {
[super dealloc];
}
@end
WhackMenu.m:
#import "WhackMain.h"
#import "MainMenu.h"
@implementation WhackMain
+(CCScene *) scene2 {
// 'scene' is an autorelease object.
CCScene *scene2 = [CCScene node];
// 'layer' is an autorelease object.
WhackMain *layer2 = [WhackMain node];
// add layer as a child to scene
[scene2 addChild: layer2];
// return the scene
return scene2;
}
-(id) init {
// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init])) {
// create and initialize a Label
CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello World" fontName:@"Marker Felt" fontSize:64];
// ask director the the window size
CGSize size = [[CCDirector sharedDirector] winSize];
// position the label on the center of the screen
label.position = ccp( size.width /2 , size.height/2 );
// add the label as a child to this Layer
[self addChild: label];
}
return self;
}
// on "dealloc" you need to release all your retained objects
- (void) dealloc {
[super dealloc];
}
@end
CCTransitionFadeTR) as well? Do they show the same behavior? – bummzack Feb 11 '12 at 22:45