I’ve made small game in Xcode 4.2.
After I played all game level, the high-score-input window will appear. I want to add NSTextField to here, so the player could type his name by keyboard.
I added NSTextField to OpenGlView, but I can’t see it on the screen. What’s the matter with this? I also try to add subview and add NSTextField, but I get the same result.
Xcode4.2, simulator is My Mac – 32bit.
NSView *view = [[NSView alloc] initWithFrame:NSRectFromCGRect(CGRectMake(0, 0, 480, 320))];
[[[CCDirector sharedDirector] openGLView] addSubview:view];
[[view layer] setZPosition:1];
//
NSTextField *textField = [[NSTextField alloc] initWithFrame:NSRectFromCGRect(CGRectMake(0, 0, 100, 40))];
[view addSubview:textField];
As the documentation for
NSOpenGLViewstates, it does not support subviews:While I’m not sure whether you’re using your own
NSOpenGLViewsubclass, or whether cocos2d provides a view itself, but it will likely have the same “limitations”.The
NSTextFieldcould be in the same window, provided it’s located such that it doesn’t overlap the OpenGL view.Otherwise, you could just implement that part of the UI in a separate
NSWindow.This sample project displays the dialog as a sheet, attached to the main window with the OpenGL view:
Project: OpenGLHighScore.zip