HUD layer not being added on my scene

狂风中的少年 提交于 2019-12-11 14:11:34

问题


I have a CCScene which already holds my gameLayer and I am trying to add HUD layer on that.But the HUD layer is not getting added in my scene, I can say that because I have set up a CCLabel on HUD layer and when I run my project, I cannot see that label.

Here's what I am doing : In my gameLayer:

+(id) scene
{

   CCScene *scene = [CCScene node];

   GameScreen *layer = [GameScreen node];
   [scene addChild: layer];

    HUDclass * otherLayer = [HUDclass node];
    [scene addChild:otherLayer];

    layer.HC = otherLayer;// HC is reference to my HUD layer in @Interface of gameLayer
    return scene;
}

And then in my HUD layer I have just added a CCLabelTTF in its init method like this :

-(id)init {

    if ((self = [super init])) {

    CCLabelTTF * label = [CCLabelTTF labelWithString:@"IN WEAPON CLASS" fontName:@"Arial"    fontSize:15];
     label.position = ccp(240,160);
     [self addChild:label];

    }

    return  self;
}

But now when I run my project I dont see that label, What am I doing wrong here ..?

Any Ideas.. ?

Thanks in advance for your time.


回答1:


hmmm, you are not adding the HUD instance to the scene. try :

    HUDclass * otherLayer = [HUDclass node];
    [scene addChild:otherLayer];

    layer.HC = otherLayer;


来源:https://stackoverflow.com/questions/11758056/hud-layer-not-being-added-on-my-scene

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!