проблема cocos2d - слой не обновляется достаточно быстро - PullRequest
0 голосов
/ 24 июля 2010

Я добавляю оверлеи к слою cocos2d при подготовке к скриншоту ...

CGSize winSize = [[CCDirector sharedDirector] winSize];

CCScene* currentScene = [[CCDirector sharedDirector] runningScene];

 GameLayer* topLayer = (GameLayer *)[currentScene.children objectAtIndex:0];

 CCSprite *middleBackground = [CCSprite spriteWithFile:@"mid_bg.png"];
 middleBackground.position = ccp(winSize.width * 0.5,winSize.height * 0.55);
 [topLayer addChild:middleBackground z:3 tag:111];

 CCSprite *bottomBackground = [CCSprite spriteWithFile:@"bot_bg.png"];
 bottomBackground.position = ccp(winSize.width * 0.5,winSize.height * 0.1);
 [topLayer addChild:bottomBackground z:3 tag:112];

 CCSprite *topBackground = [CCSprite spriteWithFile:@"top_bg.png"];
 topBackground.position = ccp(winSize.width * 0.5,winSize.height * 0.94);
 [topLayer addChild:topBackground z:3 tag:113];

 [[UIApplication sharedApplication] setStatusBarHidden:YES];

 CCSprite *topBackground2 = [CCSprite spriteWithFile:@"statusCover2.png"];
 topBackground2.position = ccp(winSize.width * 0.5,winSize.height * 0.992);
 [topLayer addChild:topBackground2 z:3 tag:114];

 [[topLayer popoverController] dismissPopoverAnimated:YES];

затем

[UIImage imageWithCGImage:UIGetScreenImage()];

Тем не менее, последний не учитывает оверлеи. Он делает скриншот слоя перед добавлением оверлеев.

Могу ли я сказать сцене / слою cocos2d обновить СЕЙЧАС?

1 Ответ

0 голосов
/ 24 июля 2010

Поскольку cocos2d является асинхронным, вы не можете сказать ему что-то подобное. Однако вы можете запланировать обратный вызов через две секунды и сделать так, чтобы этот обратный вызов делал снимок экрана.

[self schedule: @selector(screenshot:) interval:2.0];

затем определите селектор следующим образом:

-(void) screenshot:(id)sender {
  [UIImage imageWithCGImage:UIGetScreenImage()];
  [self unschedule:@selector(screenshot:)];
}

не забыл отменить это.

...