Reputation: 1321
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];
Upvotes: 0
Views: 490
Reputation: 22948
As the documentation for NSOpenGLView
states, it does not support subviews:
"An
NSOpenGLView
object cannot have subviews. You can, however, divide a singleNSOpenGLView
into multiple rendering areas using theglViewport
function."
While I'm not sure whether you're using your own NSOpenGLView
subclass, or whether cocos2d provides a view itself, but it will likely have the same "limitations".
The NSTextField
could 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
Upvotes: 5