cocos2d 问题 - 图层更新速度不够快

发布于 2024-09-11 08:31:21 字数 1344 浏览 3 评论 0原文

我正在向 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 场景/图层现在更新框架吗?

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 * 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失而复得 2024-09-18 08:31:21

因为 cocos2d 是异步的,所以你不能告诉它做类似的事情。但是,您可以安排回调在两秒内发生,并让该回调执行屏幕捕获。

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

然后像这样定义选择器:

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

不要忘记取消安排它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文