當我嘗試在cocos2d中的遊戲中顯示遊戲結束層中的最終分數時遇到問題。有一個算法可以修改我的變量increment
的值,它包含用戶的點數,然後遊戲顯示它們。如何在cocos2d中顯示比賽結果中的分數
increment = increment + 50;
[pointLabel setString: [NSString stringWithFormat: @"Points: %i", increment]];
,然後如果用戶具有或沒有在他的發揮
-(void)gameOver:(int)value punteggio:(id)punti{
if (value == 1) {
//WIN
}else if(value == 2){
if (life > 1) { // 1
life = life - 1;
for (CCSprite *spr in spriteLifeArray) {
if (life == spr.tag) {
[self removeChild:spr cleanup:YES];
}}}
else {
// LOSE
[...]
[[CCDirector sharedDirector] replaceScene:[GameOver node]];
}
}}
然後GameOverLayer被稱爲生命的功能控制。這是.h文件
@interface GameOver : CCNode {
CGSize size;
CCLabelTTF *label1;
CCLabelTTF *label2;
CCLabelTTF *labelpnt;
CCLabelTTF *labelscore;
}
-(void)restart;
這裏.m文件
@implementation GameOver
+(id) scene {
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
GameOver *layer = [GameOver node];
// add layer as a child to scene
[scene addChild: layer];
// return the scene
return scene;
}
-(id) init{
if((self=[super init])) {
size = [[CCDirector sharedDirector] winSize];
label1 = [CCLabelTTF labelWithString:@"Game Over" fontName:@"Marker Felt" fontSize:40];
label1.position = ccp(size.width/2 , size.height/2+20+50);
labelpnt = [CCLabelTTF labelWithString:@"Punteggio" fontName:@"Marker Felt" fontSize:20];
labelpnt.position = ccp(size.width/2 , size.height/2+50-100);
labelscore = [CCLabelTTF labelWithString:@"100" fontName:@"Marker Felt" fontSize:20];
[labelscore setString: [NSString stringWithFormat: @" 0 "]];
[labelscore setColor:ccc3(255, 1, 1)];
labelscore.position = ccp(size.width/2, size.height/2+50-130);
label2 = [CCLabelTTF labelWithString:@"Ricomincia" fontName:@"Marker Felt" fontSize:25];
CCMenuItemLabel *back = [CCMenuItemLabel itemWithLabel:label2 target:self selector:@selector(restart)];
CCMenu *menu= [CCMenu menuWithItems:back, nil];
menu.position = ccp(size.width/2 , size.height/2-50+50);
[self addChild: label1];
[self addChild: labelpnt];
[self addChild: labelscore];
[self addChild: menu];
}
return self;
}
-(void) restart {
[[CCDirector sharedDirector] replaceScene:[HelloWorldLayer node]];
}
我怎麼能顯示我int increment
在遊戲結束層最終值?我怎樣才能通過課程?
但是,這是爲了單人遊戲還是所有遊戲中最好的?有了這個方法,我可以傳遞類之間的值?謝謝 – TheInterestedOne 2013-02-14 18:34:56
使用不同的鍵,如@「HighScore1」,@「PlayerLife」等等。但我使用單身類來保存遊戲統計數據... – Guru 2013-02-14 18:38:23
好的,但我不想存儲數據。目前還沒有。我只想選擇單場比賽(最後一場)的比分,並將其傳遞給層上的遊戲。遊戲重新啓動或應用程序關閉後,它可能會被釋放! – TheInterestedOne 2013-02-14 19:15:18