我来自意大利,一段时间后我正在创建一个实现 HUD 的新 Cocos2D 项目。奇怪的是,HUD 曾经在我以前的项目中工作,但即使将文件移动到新项目中,什么也没有显示,只有主层......我试图完全按照 Bob Ueland 的教程(http:/ /bobueland.com/cocos2d/2011/robin-hud/),一步一步,萌芽无事可做……
但是这些是我的文件,我试图删除一些东西以使其尽可能简单,但是带有标签“arrivederci”的层总是不可见的......
可能有一个我看不到的愚蠢错误,也许它与应用程序委托有关......
威尼斯.h
#import "cocos2d.h"
#import "HudLayer.h"
@interface venezia : CCLayer
{
HudLayer *hud;
CCSprite *sfondo2;
CCLabelTTF *txt;
}
@property (nonatomic, retain) HudLayer *hud;
+(CCScene *) scene;
@end
威尼斯.m
#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
HudLayer.h
#import "cocos2d.h"
@interface HudLayer : CCLayerColor
{
CCLabelTTF *txt2;
}
@end
HudLayer.m
#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
提前谢谢你,我真的需要这个来继续我的项目,它只是一个部分,但是没有这个开发就会卡住......