我将我的游戏从cocos2d(obj-c)移植到cocos2d-x 2.x(c ++),但我真的在努力让社交功能发挥作用。是否有可能以任何方式使用下面的代码在本机objective-c和cocos2d中完美无缺。
截屏
- (UIImage*) takeScreenShot
{
[CCDirector sharedDirector].nextDeltaTimeZero = YES;
CGSize winSize = [CCDirector sharedDirector].winSize;
CCLayerColor* blankLayer = [CCLayerColor layerWithColor:ccc4(255, 255, 255, 0) width:winSize.width height:winSize.height];
blankLayer.position = ccp(winSize.width/2, winSize.height/2);
CCRenderTexture* rtx = [CCRenderTexture renderTextureWithWidth:winSize.width height:winSize.height];
[rtx begin];
[blankLayer visit];
//[[[CCDirector sharedDirector] runningScene] visit];
[layer_main visit];
[rtx end];
return [rtx getUIImage];
}
在Facebook上发布
- (void)share_score_facebook: (id) sender{
if (SYSTEM_VERSION_LESS_THAN(@"6.0")){
[AppVariables showAlert:@"Outdated iOS" message:@"You must have atleast iOS 6.0 to use the social features.\nPlease update to a newer iOS."];
return;
}
[[CCDirector sharedDirector] pause];
[[CCDirector sharedDirector] stopAnimation];
AppController *app = (AppController*) [[UIApplication sharedApplication] delegate];
UIImage * screenshot = [self takeScreenShot];
SLComposeViewController *faceBookPost = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[faceBookPost setInitialText:[NSString stringWithFormat:@"Game on! Just scored %d on Game. Can you Beat it?",total_score]];
[faceBookPost addImage:screenshot];
[faceBookPost addURL:[NSURL URLWithString:@"URL_HERE"]];
[[app navController] presentViewController:faceBookPost animated:YES completion:nil];
faceBookPost.completionHandler = ^(SLComposeViewControllerResult result)
{
[[CCDirector sharedDirector] resume];
[[CCDirector sharedDirector] startAnimation];
[[app navController] dismissViewControllerAnimated:YES completion:nil];
};
}
答案 0 :(得分:0)
您可以使用cocos2d-x编译任何Objective-C代码,但您需要修改代码以适应cocos2d-x API。你想截取屏幕截图并将其发布到Facebook,对吧?如何使用以下代替Objective-C代码?