Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Following exactly tutorials, but HUD doesn't display -

I'm from Italy, and I'm creating after a while a new Cocos2D project that implements an HUD. The strange thing is that HUD used to work in my previous project, but even moving the files in the new one, nothing displays at all, just the main layer... I've tried to follow exactly Bob Ueland's tutorial (http://bobueland.com/cocos2d/2011/robin-hud/), step by step, bud nothing to do...

However these are my files, I've tried to remove stuff to make it as simple as possible, but the layer with the label "arrivederci" is always invisible...

Probably there is a stupid error that i can't see, maybe it has something to do with app delegate...

venezia.h

Here the code: [code]

import "cocos2d.h"

import "HudLayer.h"

@interface venezia : CCLayer

{ HudLayer *hud; CCSprite *sfondo2; CCLabelTTF *txt;

}

@property (nonatomic, retain) HudLayer *hud;

+(CCScene *) scene;

@end [/code]

venezia.m [code]

import "venezia.h"

@implementation venezia @synthesize hud;

+(CCScene *) scene { CCScene *scene = [CCScene node]; venezia *layer = [venezia node]; [scene addChild: layer];

//add another layer to the scene

HudLayer *anotherLayer = [HudLayer node];
[scene addChild: anotherLayer z:14];
layer.hud = anotherLayer;


return scene;

}

  • (id) init { self = [super init]; if (self != nil) { sfondo2 = [CCSprite spriteWithFile:@"sfondo.png"]; [self addChild: sfondo2 z:1]; sfondo2.position = ccp (240, 160);

    //TESTO        
    txt = [CCLabelTTF labelWithString:@"CIAO" dimensions: CGSizeMake(400,200) alignment: UITextAlignmentCenter fontName:@"Trebuchet MS" fontSize: 16];
    txt.position = ccp (110,110);
    [self addChild: txt z:12];
    txt.visible = YES;             
    

    } return self; }

  • (void) dealloc { [super dealloc]; } @end [/code]

HudLayer.h [code]

import "cocos2d.h"

@interface HudLayer : CCLayerColor

{ CCLabelTTF *txt2;
}

@end [/code]

HudLayer.m [code]

import "HudLayer.h"

@implementation HudLayer

-(id) init

{ if( (self=[super initWithColor:ccc4(25, 225, 0, 128)])) {

    txt2 = [CCLabelTTF labelWithString:@"ARRIVEDERCI" dimensions: CGSizeMake(400,200) alignment: UITextAlignmentCenter fontName:@"Trebuchet MS" fontSize: 16];
    txt2.position = ccp (110,0);
    [self addChild: txt2 z:12];
    txt2.visible = YES;         
}

return self;

}

  • (void) dealloc

{ [super dealloc]; }

@end [/code]