我是新來的cocos2d和目標C,做了一些第一步,並有問題,我不能擊敗。我有2個場景,第一個加載一些文件,比加載後我想切換到主場景,但不能這樣做。我已經制作了加載元素的進度條,並且我想在加載完成後轉到下一個場景。但它並不能取代現場並退出應用程序。以下是PreloaderScene的部分代碼:加載完成後替換場景
+(id) scene
{
CCScene *scene = [CCScene node];
CCLayer* layer = [PreloaderScene node];
[scene addChild:layer];
return scene;
}
- (id) init
{
if ((self = [super init]))
{
int n=5;
CCLabelTTF *label = [CCLabelTTF labelWithString:@"Loading..." fontName:@"Marker Felt" fontSize:64];
CGSize size = [[CCDirector sharedDirector] winSize];
label.position = ccp(size.width /2 , size.height/2);
[self addChild: label];
CCSprite *Bar = [CCSprite spriteWithFile:@"200x30.png"];
Bar.position = ccp(size.width /2 , size.height/2-70);
[self addChild:Bar];
CCSprite *Progress = [CCSprite spriteWithFile:@"2x30.png"];
Progress.position = ccp (size.width/2-100+1, size.height/2-70);
[self addChild:Progress];
ResourceManager *Resource = [[ResourceManager alloc] init];
for (int i=1;i<=n;i++)
{
NSString *imageName =[NSString stringWithFormat:@"image%d.png",i];
[Resource LoadImage:imageName];
[Progress runAction:[CCMoveTo actionWithDuration:1 position:ccp (size.width/2-100+i/n*100, size.height/2-70)]];
[Progress runAction:[CCScaleBy actionWithDuration:1 scaleX:i/n*100 scaleY:1]];
}
[[CCDirector sharedDirector] replaceScene:MainScene];
}
return self;
}