标题:
@interface GameScene : CCScene
{
}
@property(nonatomic,weak)GameLayer *gameLayer;
@property(nonatomic,weak)HudLayer *hudLayer;
@end
在.m中实现:
@implementation GameScene
-(id)init {
if ((self = [super init])) {
_gameLayer = [GameLayer node];
[self addChild:_gameLayer z:0];
_hudLayer = [HudLayer node];
[self addChild:_hudLayer z:1];
_hudLayer.dPad.delegate=_gameLayer;
_hudLayer.jPad.delegate=_gameLayer;
_hudLayer.aPad.delegate=_gameLayer;
_gameLayer.hud=_hudLayer;
}
return self;
}
@end
任何建议?
谢谢你的回复,这是我实现hud图层的方式
头:
@interface HudLayer : CCLayer {
CCLabelTTF *_lifeLabel;
CCLabelTTF *_enemyLabel;
}
@property(nonatomic,weak)SimpleDPad *dPad;
@property(nonatomic, weak)SimpleJPad *jPad;
@property(nonatomic, weak)SimpleAPad *aPad;
-(void)setLifeString:(NSString *)string;
-(void)setEnemyString:(NSString *)estring;
@end
实施.m:
@implementation HudLayer
-(id)init{
if((self=[super init])){
_dPad=[SimpleDPad dPadWithFile:@"pad.png" radius:50];
_dPad.position=ccp(90, 60);
_dPad.opacity=180;
[self addChild:_dPad];
_jPad=[SimpleJPad jPadWithFile:@"jumb.png" radius:30];
_jPad.position=ccp(450, 60);
_jPad.opacity=100;
[self addChild:_jPad];
_aPad=[SimpleAPad aPadWithFile:@"jumb.png" radius:30];
_aPad.position=ccp(390, 60);
_aPad.opacity=100;
[self addChild:_aPad];
//lifelabel
_lifeLabel = [CCLabelTTF labelWithString:@"" fontName:@"Marker Felt" fontSize:25];
_lifeLabel.position = ccp(90, 260);
[self addChild:_lifeLabel];
//enemy label
_enemyLabel = [CCLabelTTF labelWithString:@"" fontName:@"Marker Felt" fontSize:25];
_enemyLabel.position = ccp(380, 260);
[self addChild:_enemyLabel];
}
return self;
}
-(void)setLifeString:(NSString *)string{
_lifeLabel.string=string;
}
-(void)setEnemyString:(NSString *)estring{
_enemyLabel.string=estring;
}
@end