我有一个Gamehud
我想显示对象名称的地方。主场景中有很多对象/精灵我想做的是在Gamehud
.
问题是如果我Gamehud
在CCsprite
类中分配它会创建新实例并且不会更新 current Gamehud
。如果我使用什么GameHUD *gamehud= (GameHUD *)[self.parent getChildByTag:99];
都没有发生的事情,我无法将对象发送到 GameHud 类。
那么在ccsprite or ccnode
课堂上更新游戏界面的正确方法是什么?
主要场景;
-(id) init
{
if ((self = [super init]))
{
gameHud = [GameHUD gamehud];
[self addChild:gameHud z:2 tag:99];
}
}
我的游戏界面
+(id) gamehud
{
return [[self alloc] init];
}
-(id) init
{
if ((self = [super init]))
{
//bunch of labels
}
}
-(void)showName: :(Object *)obj
{
NSLog(@"Object name is %@", obj.name);
[_labelSpeed setString:obj.name];
}
在对象类中:CCSprite
-(void) onTouch
{
//obj is the object with name property that I want to use
GameHUD *gamehud= (GameHUD *)[self.parent getChildByTag:99]; // does not send the obj to gamehud and showName is not called
//GameHud *gamehud= [GameHud alloc] init]; // this displays nslog but doesnt update _label
[gamehud showName:obj];
}