将相机放在Cocos2d-3.0的背景中

时间:2014-02-21 10:10:37

标签: ios cocos2d-iphone

作为我游戏的背景,我想把iphone内置摄像头的当前视图放在cocos2d-iphone-3.0中找不到与之相关的任何内容。我试过这个http://www.raywenderlich.com/3997/augmented-reality-tutorial-for-ios,但它不会帮助。

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
CCGLView *glView = [CCGLView viewWithFrame:[self.window bounds]
                               pixelFormat:kEAGLColorFormatRGBA8 depthFormat:0];

[CCDirector sharedDirector].view.backgroundColor = [UIColor clearColor];
[CCDirector sharedDirector].view.opaque = NO;

// set value for glClearColor
glClearColor(0.0, 0.0, 0.0, 0.0);

// prepare the overlay view and add it to the window
overlay = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
overlay.opaque = NO;
overlay.backgroundColor=[UIColor clearColor];
[self.window addSubview:overlay];

#define CAMERA_TRANSFORM  1.24299

UIImagePickerController *uip;

@try {
    uip = [[UIImagePickerController alloc] init] ;
    uip.sourceType = UIImagePickerControllerSourceTypeCamera;
    uip.showsCameraControls = NO;
    uip.toolbarHidden = YES;
    uip.navigationBarHidden = YES;
    uip.wantsFullScreenLayout = YES;
    uip.cameraViewTransform = CGAffineTransformScale(uip.cameraViewTransform,
                                                     CAMERA_TRANSFORM, CAMERA_TRANSFORM);
}
@catch (NSException * e) {
    uip = nil;
}
@finally {
    if(uip) {
        [overlay addSubview:[uip view]];
    }
}
[CCDirector sharedDirector].view = glView;
 #ifdef APPORTABLE
if([cocos2dSetup[CCSetupScreenMode] isEqual:CCScreenModeFixed])
    [UIScreen mainScreen].currentMode = [UIScreenMode emulatedMode:UIScreenAspectFitEmulationMode];
else
   [UIScreen mainScreen].currentMode = [UIScreenMode emulatedMode:UIScreenScaledAspectFitEmulationMode];
#endif

// Configure CCFileUtils to work with SpriteBuilder
[CCBReader configureCCFileUtils];

// Do any extra configuration of Cocos2d here (the example line changes the pixel format for faster rendering, but with less colors)
//[cocos2dSetup setObject:kEAGLColorFormatRGB565 forKey:CCConfigPixelFormat];

[self setupCocos2dWithOptions:cocos2dSetup];
[self createAdmobAds];

return YES;
 }

提前完成

1 个答案:

答案 0 :(得分:0)

请参阅:

-(void) setIsOverlayingDeviceCamera: (BOOL) aBool
在CCNodeController中