我正在为大学做一个iPhone应用程序(游戏)。我正在访问HUD课程,因此我可以在游戏进行过程中更新标签。我有一个糟糕的架构吗?或者我该怎么做?
@implementation HUD
@synthesize statBar;
@synthesize levelText;
@synthesize label;
@synthesize level;
- (id) init {
if((self = [super init])) {
CGSize winSize = [[CCDirector sharedDirector] winSize];
statBar = [CCSprite spriteWithFile:@"statbar.png"];
statBar.position = ccp(winSize.width/2, winSize.height-10);
levelText = [self createLevelText:10]; // testing purposes
levelText.position = ccp(((winSize.width)-(winSize.width)+20), winSize.height-10);
levelText.color = ccBLACK;
[self addChild:statBar];
[self addChild:levelText];
}
return self; // shouldnt reach this
}
- (CCLabelTTF *) createLevelText:(int)levelNo {
level = [NSString stringWithFormat:@"LVL: %d", levelNo];
label = [CCLabelTTF labelWithString:(NSString*) level fontName:@"CharlemagneStd-Bold.otf" fontSize:10];
//[label setString:(NSString *) level];
return label;
}
@end
CCLayer *hudLayer;
int hudTag;
+(void) goPlay
{
hudLayer = [HUD node];
CCLayer *playLayer = [PlayLayer node];
hudTag = playLayer.tag;
[SceneManager goWithHud: playLayer: hudLayer: hudTag];
}
+ (CCScene *) goWithHud:(CCLayer *) playLayer:(CCLayer *) hudLayer:(int)hudTag
{
CCDirector *director = [CCDirector sharedDirector];
CCScene *newScene = [CCScene node];
[newScene addChild: playLayer];
[newScene addChild: hudLayer z:0 tag:hudTag];
if([director runningScene])
[director replaceScene:newScene];
else
[director runWithScene:newScene];
return newScene;
}
+(void)setScoreString:(int *)levelNo:(CCLayer *) hudLayer
{
NSString *string = [NSString stringWithFormat:@"LVL: %d", levelNo];
hudLayer.levelText = string;
}
-(void)updateScore
{
HUD *obj = (HUD *)[self getChildByTag:hudTag];
[obj setScoreString:@"100"];
}