0

I have task to make simple app from three Views:

  • in first: UITableView (it needs to be first View when app starts)
  • in second: UITextField
  • in third: Cocos2d Layer

And maybe one more View for menu to switch between them. How can I mix ViewControllers and Layers in one project? Do i need start project from Xcode or Cocos2d template?

Olex
  • 1,656
  • 3
  • 20
  • 38

1 Answers1

1

One possible approach is starting with a Cocos2D project and then using CCUIViewWrapper to display any view as a CCNode. This approach is the best one if you can handle all of your views inside of the same Cocos2D scene.

If you are planning of building, e.g., a navigation controller based app, then the opposite strategy could be more adequate: start with a "normal" app and then, when you need it (i.e., in your third view controller), add Cocos2d's GLView to your view controller view:

[myViewController.view.layer addSublayer:[[CCDirector sharedDirector] glView].layer];

or:

[myViewController.view addSubview:[[CCDirector sharedDirector] glView]];

You will need to import QuartzCore/QuartzCore.h to be allowed to use CALayers.

sergio
  • 68,819
  • 11
  • 102
  • 123
  • 1
    In fact, The second approach would be more easy to use (just an opinion.) – viral Oct 18 '12 at 11:25
  • i4Apple yes, in my case second way is more appropriate, because I need to have possibility to use navigation controller to switch between first and second Views – Olex Oct 18 '12 at 11:33
  • One more question: how I can import cocos2d files to project correctly? I added the libs folder and few frameworks what is cocos needed to work to the Xcode by dragging them into project. But it's many ARC warnings when i try to build – Olex Oct 18 '12 at 19:49
  • 1
    You should disable arc for all the Cocos2d files: http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project – sergio Oct 18 '12 at 20:01