i want to create a new view in Cocos2d programmatically
can you help me on how can i do this? thanks
You can add uiviews to cocos2d with this line
[[[[CCDirector sharedDirector] glView] window] addSubview: yourUIView];
Related
I´m creating a GLK view on iOS5.
First, i create the context.
GLKView *view = (GLKView *)self.view;
view.context = self.context;
view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
[self setupGL];
Second, i draw a triangle moving.
This works.
Now, i want to create a view over the GLKview. So, i used the Storyboard, to draw a View (HUDView) with background red, and i put it over the main view. When i run the app, only openGL appear, i assume that red background view is drawing behind GLKView. Why?
I have tried to use on Hudview -> viewDidLoad
[self bringSubviewToFront:self];
But the problem nothing happen.
Any idea how could i solve this problem????
Thanks in advance.
I have found a sample that solve the problem. Glfun is a sample where a openGL layer is drawn, and you can add a hud view over it. Hopes help people :D
I want to add an instruction page where instruction written in UITextView. How to do it in Cocos2d. Because this is a game page and I want to take menu transaction effects of cocos2d like CCTransitionRadialCCW.
I wrote this code
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(10,60, 300,360)];
textView.backgroundColor = [UIColor clearColor];
textView.text = #"I am First enemy";
[textView setEditable:NO];
[[[CCDirector sharedDirector]openGLView]addSubview:textView];
But there is problem that it is added to the main CCDirector page, while I am writing this code
// [[[CCDirector sharedDirector]openGLView]addSubview:textView];
// replaced by :-
[self addChild:textView];
It gives me error. Please tell me how to add UITextView in CCScene or CCLayer.
I know that [self addChild:(CCNode *)node];
addChild: method needs CCNode so please tell me that how can typecast or convert UITextView object to CCNode.
If there is some alternate option for that please tell me .Like CCLabelTTF is alternate for UILabel, is there alternate for UITableView in Cocos2d-iphone.
Thanks in advance
Have a look at CCTableView: http://www.cocos2d-iphone.org/archives/943.
Combining UIKit and Cocos2D in such a way that you have the interleaving you have mentioned is likely to be very difficult, because everything done in Cocos2D is drawn in one OpenGL view. When you add a UIView, you can only add it in front of or behind Cocos2D's view.
No matter which way you're adding the UIView to cocos2d, it will not be animated by the cocos2d transition effects because simply speaking the UIView objects exist outside the OpenGL view that cocos2d uses (and animates in the case of transitions).
Adding UIViews to a cocos2d view as in your first example code is correct. But in order to position the view like a node, you should consider using the CCUIViewWrapper.
I want to add a UiView on the CCDirector and a scene on that UIView.
Actually i have some custom Cocoa touch control and that i want to use in my game and above that i need a scene.
Currently i am doing like this.
[[[CCDirector sharedDirector] openGLView] addSubview:gridViewController.view];
and after that line i do
[[CCDirector sharedDirector] runWithScene:[MYScene scene]];
[MYScene scene] returns a CCScene instance.
But what happens that on my custom cocoa touch control is visible but my scene is not visible at all.
Can any one guide me for that how i can accomplish my task.
You should try the opposite approach and have the UIView handled as a CCNode, then add the node to the scene.
There is even a class that makes this easily possible: CCUIViewWrapper.
If you use it, you can do the following:
CCUIViewWrapper* wrapper = [CCUIViewWrapper wrapperForUIView:view];
wrapper.contentSize = view.frame.size;
[self addChild:wrapper z:1 tag:LayerTagUILayer];
and you will get both the UIView and the scene added to CCDirector.glView. The UIView can be any, you can even define it in IB.
Hi Friends'
i am new to using cocos2d application , and i want to build a grid of images using a single square image.
i make that in UIImageview now i want to ask that how can i add that...
if i use [self addchild: (CCNode)square] it show error .
thanks for any help in advance
You do not use UIImageView's with cocos2d.
Try this.
CCSprite *square = [CCSprite spriteWithFile:#"yourimage.png"];
[self addChild:square];
I'm presuming self is a CCLayer.
Sounds like you need up on some basics.
There are some good beginner tutorials here.
http://www.learn-cocos2d.com/
I need to play a video into a cocos2d project.. and my question is: how can I put MPMoviePlayerController into my view like this:?
UIView *theView = [[CCDirector sharedDirector] openGLView];
thanks very much!!
You can't put controllers into views. However, you can put the views that they control into a view. Try this:
// instantiate and configure your MPMoviePlayerController here, c
// call it movieController
[theView addSubview:movieController.view];
disclaimer: I'm at the office so I have no way of knowing if this will work.