As the title said, I am having a problem adding cocos2d scene into UIView layer. I want to use spine-cocos2d-objc
in my existing project, but i face some issues.
I found similar question here but unfortunately, no answer.
spine-cocos2d-objc
is successfully integrated in my existing project, but i have no clue how to create a scene inside some of my view controller.
In the example, it launch full screen of cocos2d scene in AppDelegate
[self setupCocos2dWithOptions:@{
CCSetupDepthFormat: @GL_DEPTH24_STENCIL8,
CCSetupTabletScale2X: @YES,
CCSetupScreenMode: CCScreenModeFixed,
CCSetupScreenOrientation: CCScreenOrientationPortrait,
CCSetupShowDebugStats: @YES,
}];
[[CCDirector sharedDirector] runWithScene:[SpineboyExample scene]];
But in my project, i just need to launch cocos2d in some view controller. Notes: I know that cocos2d is such an old framework. But I think, this is the only option I had.
SpriteKit, actually much easier than cocos2D in terms of integrating with UIKit, but sadly, Spine runtime that using SpriteKit has no support for newest Spine features.
Any ideas?
EDIT
This is by far the closest solution i have tried. I tried to embed CCScene from Cocos2D into my UIView using this
- (void)setupCocos2D {
CCGLView *glView = [CCGLView viewWithFrame:[[self view] frame]
pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8
depthFormat:0 // GL_DEPTH_COMPONENT16_OES
];
glView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view insertSubview:glView atIndex:0];
[[CCDirector sharedDirector] setView:glView];
CCScene *scene = [GoblinsExample scene];
[[CCDirector sharedDirector] runWithScene:scene];
}
Right now, I can see CCDirectorDisplayLink
in my view layer. But unfortunately, all that i got is only white page. The scene is successfully load all assets that needed, but still it does not appear in my UIView
.
Any help would be appreciated. Thank you!