2013-03-08 1 views
0

나는 상황을 더 잘 설명하려고 노력한다.인쇄 점수 및 고득점

변수는 다음과 같습니다

int punteggio; 

CCLabelTTF *labelPunteggio; 

그런 다음 초기화 metod에 내가 화면에 내 점수를 인쇄 :

- (id)init { 
    if ((self = [super init])) { 

    // PUNTEGGIO 
    labelPunteggio = [CCLabelTTF labelWithString:@"0000" fontName:@"Marker Felt" fontSize:13]; 

    [self addChild:labelPunteggio]; 
    .... 
    } 
} 

그리고 이것은 Punteggio에 점수를 추가 할 수있는 기능입니다 : 예를 들어, 모든 나는 몬스터를 죽일 때 10 점을 더한다.

-(void)aggiungiPunti 
{ 
    punteggio = punteggio +0001; 

    [labelPunteggio setString:[NSString stringWithFormat:@"%d", punteggio]]; 
} 

하지만 이제 플레이어가 게임을 끝내면 점수를 저장하는 방법을 모르겠습니다. 내가 생각이 점수를 저장하려면, 다음, 화면에 을 높은 점수를 인쇄하는 것에 대한

-(void) setScore:(int)score 
{ 
    punteggio = highScore; 

    if (punteggio>highScore) 
    { 
     highScore = punteggio; 
    } 
} 

감사합니다!

답변

0

highScore = punteggio를 설정했기 때문에 setScore 방법이 작동하지 않을 수 있습니다. if는 절대로 맞지 않습니다. 시도 :

-(void) setHighScore:(int) newScore { 
    if(newScore>highScore) highScore = newScore; 
} 

과 때마다 현재 점수

-(void)aggiungiPunti 
{ 
    punteggio = punteggio +0001; 
    [labelPunteggio setString:[NSString stringWithFormat:@"%d", punteggio]]; 
    [self setHighScore:punteggio]; 
} 

최고 점수 변수가 항상 설정됩니다 이런 식으로, 게임 플레이의 어떤 상태를 업데이트합니다. 현재 게임의 시작 부분에서 highScore를 현재의 highScore로 설정하는 것을 잊지 마십시오.

+0

감사합니다. 나는 시도하지만 작동하지 않습니다 ... 이 같은 init metod에서 인쇄합니다. labelScore = [CCLabelTTF labelWithString : @ "0000"fontName : @ "Marker Felt"fontSize : 13]; [self addChild : labelScore]; labelhighScore = [CCLabelTTF labelWithString : @ "0"fontName : @ "Marker Felt"fontSize : 13]; [self addChild : labelhighScore]; 최고 점수는 변경되지만 항상 0입니다. –