Exiting EAGLView and returning to UIKit

I’m working on an app that requires a section controlled by UIKit and a small game built in cocos2d-x. Once I’ve opened the EAGLView and called CCApplication::sharedApplication().run();, I’d like to be able to move from the game back to the UIKit section. How can I target the UIView or the UIViewController that instantiated my EAGLView from within the EAGLView? I can use CCDirector::sharedDirector()->getOpenGLView() to get a reference to a CC_GLVIEW, but there are no methods on this object that reference the parent UIView or UIViewController. I’d love to be able to call a method assigned to this UIViewController from within a CCScene’s method in my game.

Any help would be appreciated.

CC_GLVIEW = cocos2d::CCEGLView, invokes [EAGLView sharedEGLView]
Maybe you can start from platform/ios/EAGLView.mm, .h, it’s an objc class inherited from UIView.

Jason M wrote:

I’m working on an app that requires a section controlled by UIKit and a small game built in cocos2d-x. Once I’ve opened the EAGLView and called CCApplication::sharedApplication().run();, I’d like to be able to move from the game back to the UIKit section. How can I target the UIView or the UIViewController that instantiated my EAGLView from within the EAGLView? I can use CCDirector::sharedDirector()->getOpenGLView() to get a reference to a CC_GLVIEW, but there are no methods on this object that reference the parent UIView or UIViewController. I’d love to be able to call a method assigned to this UIViewController from within a CCScene’s method in my game.
>
>
Any help would be appreciated.

Currently I would like to do the same too to return to previous UIViewController.

I have succeeded in returning back by assign controllerDelegate in EAGLView,
But once I retried a lot of times (from Cocos2DXViewController <-> normal UIViewController),
The touch motion becomes slower to react.

When I return to previous UIViewController, I have killed the CCApplication and restarted each time.
Is there anything that I have not released? (For example any static instance?)

Or is there any better implementation for this?

1 Like

I also have the same problem, did you manage to solve it?

I’m able to solve the issue by enforcing a strong UIViewController (retained in AppController.mm) that contains EAGLView.
Do not kill CCApplication nor the custom UIViewController when returning back to previous UIViewController, maintain it in AppController.mm so that it can be reused. You might need to handle next start up scene (poping and destruct unused scene).