0

私が抱えている問題にますます不満を募らせているので、あなたが提供できるアドバイスに非常に感謝しています.また、私が抱えている問題は私の知識/理解の欠如が原因であることにも感謝しています.

知識を深めて自分自身を伸ばすために、プレーヤーのスコアリングと、時間、健康などを処理する 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 を表示する必要があることを示していますが、ラベル自体は更新されません。

私が問題を誤解していることを非常に認識しているので、アドバイスをいただければ幸いです。問題は、私が更新しているレイヤーが、私が信じているレイヤーではないことに関係していると思います....

前もって感謝します。

4

2 に答える 2

0

最後に、この問題を解決するために、文字列を空の文字列に設定してから、文字列に再設定しました

[label setString:@""];
[label setString:yourString]; 
于 2014-01-25T13:51:57.273 に答える
0

PlayerStats クラス ヘッダーでインスタンス変数として CCLabelTTF *score を宣言しました。コードから離れて夜を過ごすと、どんな違いが生まれますか。

于 2012-08-08T07:51:32.703 に答える