AppDelegate が異なるウィンドウで同時に実行されている Cocos2d のいくつかの異なるインスタンスを管理できるように、Cocos2d に独自の NSWindowController を含めることができるようにしたいと考えています。
NSWindowController サブクラスで Cocos2d をロードするたびに、OpenGl ビューに空のビューが表示されます。
シーンが正しくレンダリングされないのはなぜですか?
Cocos2dWindowController.h
#import <Cocoa/Cocoa.h>
#import "cocos2d.h"
@interface Cocos2dWindowController : NSWindowController <CCDirectorDelegate>{
CCGLView *glView_;
}
@property (strong) IBOutlet CCGLView *glView;
@end
Cocos2dWindowController.mm
#import "Cocos2dWindowController.h"
#import "PuzzleWorld.h"
@interface Cocos2dWindowController ()
@end
@implementation Cocos2dWindowController
@synthesize glView=glView_;
- (id)initWithWindow:(NSWindow *)window
{
self = [super initWithWindow:window];
if (self) {
// Initialization code here.
}
return self;
}
- (void)windowDidLoad
{
[super windowDidLoad];
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
//Check to see if the view is empty prior to launching
CCDirectorMac *director = (CCDirectorMac*) [CCDirector sharedDirector];
// enable FPS and SPF
[director setDisplayStats:YES];
// connect the OpenGL view with the director
[director setView:glView_];
director.delegate = self;
// EXPERIMENTAL stuff.
// 'Effects' don't work correctly when autoscale is turned on.
// Use kCCDirectorResize_NoScale if you don't want auto-scaling.
[director setResizeMode:kCCDirectorResize_AutoScale];
// Enable "moving" mouse event. Default no.
[self.window setAcceptsMouseMovedEvents:NO];
// Center main window
[self.window center];
CCScene *scene = [CCScene node];
[scene addChild:[PuzzleWorld node]];
// Run whatever scene we'd like to run here.
if(director.runningScene)
[director replaceScene:scene];
else
[director runWithScene:scene];
}
//Override the close action to kill off Cocos2d and OpenGl
- (void)close{
[super close];
//Check to see if the view is empty prior to launching
CCDirectorMac *director = (CCDirectorMac*) [CCDirector sharedDirector];
[director setDelegate:nil];
[director end];
}
@end
これは、Xcode バージョン 4.6 (4H127) を搭載した Cocos2d 2.0 で発生しています。