Pregunta

I want to be able to have Cocos2d contain in it's own NSWindowController such that the AppDelegate will be able to manage several different instances of Cocos2d running that the same time in different windows.

Each time I load Cocos2d in the NSWindowController subclass, I get a blank view in the OpenGl View.

Resulting OpenGL View subclassed to CCGLView

Why is it not rendering the scene properly?

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

Xib Configuration

This is occurring on Cocos2d 2.0 with Xcode Version 4.6 (4H127)

¿Fue útil?

Solución

I can't tell you why your screen is white. If you base it off of the Cocos2D Mac template, check the MainWindow.xib. The Cocos2D view spans the entire window, so just resize it and work with that.

What I can tell you is that your goal of running multiple cocos2d views is futile: cocos2d only supports a single view.

Support for multiple views has been on the roadmap for years, and it doesn't look like it'll come anytime soon. It's a non-trivial change as well, given how reliant cocos2d is on Singletons for many core classes (Director, ActionManager, Scheduler, Caches, ...).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top