cocos2d中如何切换场景?我有我的主类“HellowWorldLayer.h/.m”,但我似乎无法正确切换场景。我努力了 :
[[CCDirector sharedDirector] replaceScene:[Race node]];
//And
[[CCDirector sharedDirector] replaceScene:[Race Scene]];
我放置了一个断点,我可以看到它正在进入新场景,但我添加到新场景的按钮没有显示。我正在正确创建按钮。然后我将它添加到新场景的屏幕上,如下所示:
[self addChild:Menu];
我刚刚从 HolloWorldLayer.m/.h 中获取了所有代码并将其复制到新场景(类)中,但我无法正确转换。我是 xcode 和 cocos2d 的新手,如果这真的很简单,我很抱歉。
Race.m
#import "Race.h"
#import "Intermediary.h"
@implementation Race
+(CCScene *) scene{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
Race *layer = [Race node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
-(id) init{
if( (self=[super init]) ) {
NSLog(@"Racing!");
CCLabelTTF *startLbl = [CCLabelTTF labelWithString:@"Start" fontName:@"Marker Felt" fontSize:20];
CCMenuItemLabel *startMenu = [CCMenuItemLabel itemWithLabel:startLbl block:^(id sender) {
NSLog(@"I have been pushed!");
}];
startMenu.position = ccp(50,50);
CCMenu *Menu = [CCMenu menuWithItems:startMenu, nil];
[self addChild:Menu];
}
return self;
}
@end
你的代码对我有用。
这是示例:Download
使用过渡以获得更好的外观。
[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[Race scene] ]];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)