3
votes

I'm new to iOS and Cocos development.

I currently have a basic app going on in my HelloWorldLayer class. It contains my sprites and touch interaction methods and all is well.

I'm trying to add another "panel" (UIView?) over top of what is currently seen. Eventually this panel will have buttons or other things that will interact with the main canvas.

How can I include another UIView onto the canvas screen? Through my appDelegate, or my HelloWorldLayer?

Thanks

1

1 Answers

2
votes

Here is one way to do it. I've used UITextView here but you could use the approach for any descendant of UIView. Bear in mind that UIKit's y coordinate is zero at the top-left of the screen, whereas Cocos2D's is zero at the bottom left.

// Make your subview
UITextView* t = [[UITextView alloc] initWithFrame: CGRectMake(10, 10, 200, 200)];
t.backgroundColor = [UIColor blackColor];
t.textColor = [UIColor whiteColor];
t.text = @"Hello UIKit!";
t.editable = NO;

// Add it as a subview of the Cocos2D view
UIView* cocosView = [[CCDirector sharedDirector] openGLView];
[cocosView addSubview:t];

Alternatively you could try Blue Ether's CCUIViewWrapper, repository here.