简体   繁体   English

如何在cocos2d-iphone中的CCLayer或CCScene中添加UITextView

[英]How to add UITextView in CCLayer or CCScene in cocos2d-iphone

I want to add an instruction page where instruction written in UITextView. 我想添加一个指令页面,其中指令以UITextView编写。 How to do it in Cocos2d. 在Cocos2d中如何做。 Because this is a game page and I want to take menu transaction effects of cocos2d like CCTransitionRadialCCW. 因为这是一个游戏页面,所以我想采用cocos2d的菜单事务效果,例如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主页的问题。

 // [[[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. 请告诉我如何在CCScene或CCLayer中添加UITextView。

I know that [self addChild:(CCNode *)node]; 我知道[self addChild:(CCNode *)node];

addChild: method needs CCNode so please tell me that how can typecast or convert UITextView object to CCNode. addChild:方法需要CCNode,所以请告诉我如何将类型转换或转换UITextView对象转换为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. 如果有其他替代方法,请告诉我。就像CCLabelTTF是UILabel的替代方法,Cocos2d-iphone中的UITableView是否有替代方法。

Thanks in advance 提前致谢

Have a look at CCTableView: http://www.cocos2d-iphone.org/archives/943 . 看看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. 以这样一种方式组合UIKit和Cocos2D可能很困难,因为在Cocos2D中完成的所有操作均在一个OpenGL视图中绘制。 When you add a UIView, you can only add it in front of or behind Cocos2D's view. 添加UIView时,只能将其添加到Cocos2D视图的前面或后面。

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). 不管您以哪种方式将UIView添加到cocos2d,cocos2d过渡效果都不会对其进行动画处理,因为简单地说,UIView对象存在于cocos2d使用的OpenGL视图之外(并且在过渡时进行动画处理)。

Adding UIViews to a cocos2d view as in your first example code is correct. 如您的第一个示例代码所示,将UIViews添加到cocos2d视图是正确的。 But in order to position the view like a node, you should consider using the CCUIViewWrapper . 但是,为了将视图定位为节点,您应该考虑使用CCUIViewWrapper

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM