开发者

Cocos2d:Add uilabel in scene

I draw a cocos2d scene in window and now want to add a label on开发者_StackOverflow中文版 top of the scene... Any idea?? Thanks


You should use CCLabel instead of UILabel when using cocos2d.

First you create a label, then you add the label to your scene.

Have a look here : http://www.cocos2d-iphone.org/api-ref/latest-stable/interface_c_c_label.html


If you want to use Cocos native Label class: add any CCLabel - the are plenty of them - to your CCScene.

CCLabel * label = [CCLabel labelWithString:@"MyString" 
                                  fontName:@"Arial" 
                                  fontSize:12.0];
// you could sort your layers by "Z" - here 99 (default:0)
[self addChild:label z:99]; 

If you want to use UILabel.. may be you could just add your UILabel to the window class located in your application delegate class "myapp_delegate.m" . May be you should add an UIView first.


In the new version of Cocos2d there is no CCLabel instead there is CCLabelTTF and then your code would be

CCLabelTTF * label = [CCLabelTTF labelWithString:@"MyString" fontName:@"Arial" fontSize:12.0];

[self addChild:label z:99];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜