So far I am using the cocos2d engine to create a game and I want to implement a QR reader.
So far I've created a CCScene, the CCScene has a menu button and it leads to a onScan Method:
-(void) onScan:(id)sender{
// ADD: present a barcode reader that scans from the camera feed
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
ZBarImageScanner *scanner = reader.scanner;
// TODO: (optional) additional reader configuration here
// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
// present and release the controller
[self presentModalViewController: reader
animated: YES];
[reader release];
}
I understand that this works on a standard ViewController class but I am wondering how to best implement this to work with the cocos2d engine on my CCScene
Any help would be appreciated Thanks!
If you come from a typical cocos2d-iphone project which was created using the Xcode template, I think you should have a RootViewController class in your app. The only instance of the RootViewController is created in applicationDidFinishLaunching: in AppDelegate.m.
You can somehow save a global reference of your root UIViewController, for example, to implement a class method in RootViewController:
and change the initialization in AppDelegate.m to:
then use it to present your UIViewController:
In cocos2d-iphone, the CCDirector IS the UIViewController.
So, just do this: