开发者

cocos2d problem - layer not updating quick enough

开发者 https://www.devze.com 2023-01-08 10:11 出处:网络
i am adding overlays to a cocos2d layer in preparation for a screenshot... CGSize winSize = [[CCDirector sharedDirector] winSize];

i am adding overlays to a cocos2d layer in preparation for a screenshot...

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开发者_如何学C * 0.5,winSize.height * 0.992);
 [topLayer addChild:topBackground2 z:3 tag:114];

 [[topLayer popoverController] dismissPopoverAnimated:YES];

then

[UIImage imageWithCGImage:UIGetScreenImage()];

However the later is not taking the overlays into account. It is taking a screenshot of the layer before the overlays are added.

Is there anyway I can tell the cocos2d scene/layer to update the frame NOW?


Because cocos2d is asynchronous you can't tell it to do something like that. However, you can schedule a callback to happen in two seconds and have that callback do the screen capture.

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

then define the selector like this:

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

don't forgot to unschedule it.

0

精彩评论

暂无评论...
验证码 换一张
取 消