私が抱えている問題にますます不満を募らせているので、あなたが提供できるアドバイスに非常に感謝しています.また、私が抱えている問題は私の知識/理解の欠如が原因であることにも感謝しています.
知識を深めて自分自身を伸ばすために、プレーヤーのスコアリングと、時間、健康などを処理する PlayerStats クラスを作成することにしました。
次のように GameLevelLayer および PlayerStats クラスを実装しています。
GameLevelLayer.m は次のとおりです。
#import "GameLevelLayer.h"
#import "Player.h"
#import "PlayerStats.h"
@interface GameLevelLayer() {
CCTMXTiledMap *map;
Player *player;
PlayerStats *playerStats;
}
@end
@implementation GameLevelLayer
@synthesize grabber = _grabber;
+(CCScene *) scene
{
CCScene *scene = [CCScene node];
GameLevelLayer *layer = [GameLevelLayer node];
PlayerStats *hudLayer = [PlayerStats node];
[scene addChild: layer];
[scene addChild: hudLayer];
return scene;
}
-(id) init {
if( (self=[super init]) ) {
CGSize screenSize = [[CCDirector sharedDirector] winSize];
playerStats = [[PlayerStats alloc]init];
...........
}
PlayerStats.m は次のとおりです。
-(id) init
{
if ((self = [super init])) {
CGSize screenSize = [[CCDirector sharedDirector] winSize];
score = [CCLabelTTF labelWithString:@"Score : 0" dimensions:CGSizeMake(100,20) hAlignment:UITextAlignmentRight fontName:@"Marker Felt" fontSize:(18.0)];
int margin = 5;
score.position = ccp(screenSize.width - (score.contentSize.width/2) - margin, score.contentSize.height/2 + margin);
[self addChild:score z:99];
}
return self;
}
-(void)numberOfItemsCollected:(int)collected {
NSString *str = [score string];
CCLOG(@"What does the label say %@", str);
// This is actually displaying the correct string of what the score should be ..
[score setString:[NSString stringWithFormat:@"Score : %d", collected]];
}
(GameLevelLayer.m から) いつ開始するか
[playerStats numberOfItemsCollected:5];
CCLog は、ラベルが Score : 5 を表示する必要があることを示していますが、ラベル自体は更新されません。
私が問題を誤解していることを非常に認識しているので、アドバイスをいただければ幸いです。問題は、私が更新しているレイヤーが、私が信じているレイヤーではないことに関係していると思います....
前もって感謝します。