我想创建一个简单的图层来显示一些信息,例如分数。
我设法做到了,但我不确定它是否正确:
#import "InformationLayer.h"
#import "GameScene.h"
@implementation InformationLayer
-(void) draw
{
// Complete clear of the screen
[self removeAllChildrenWithCleanup:true];
// Draw my score
[self DrawScore];
}
- (void)DrawScore
{
// create and initialize a label
NSString* l_sScore = [NSString stringWithFormat:@"Score : %d", [[GameScene sharedGameScene] iScore]];
CCLabelTTF* label = [CCLabelTTF labelWithString:l_sScore fontName:@"Marker Felt" fontSize:32];
// get the window (screen) size from CCDirector
CGSize size = [[CCDirector sharedDirector] winSize];
// position the label at the center of the screen
label.position = CGPointMake(size.width - ([label texture].contentSize.width / 2), size.height*2.0/3.0);
// add the label as a child to this Layer
[self addChild:label];
}
@end
我一直在处理我的场景和图层,我真的不喜欢清除所有图层然后重新绘制所有内容。在我看来,这完全是矫枉过正!尽管如此,它仍然可以完成工作......
由于我处于学习曲线的底部,所以我想尽快做...我可以在这里做点更好的事情吗?