我又回来了抱歉! :)
如果可能的话,只需要一个快速的手,我希望能够计算在我建立的这个滑块拼图中所做的移动次数。到目前为止我所做的是:
·H
int moves;
CCLabel *moveLabel;
的.m
moveLabel = [[CCLabel labelWithString: [NSString stringWithFormat:@"Moves: %d", moves] dimensions: CGSizeMake(130, 27) alignment: UITextAlignmentRight fontName:@"Marker Felt" fontSize: 25.0] retain];
moveLabel.position = ccp(55,430);
[self schedule: @selector(tick3:) interval:1.0];
[self addChild: moveLabel];
处理瓷砖交换的方法是这样的,所以我添加了动作++;在底部:
-(void) changeWithTileA: (Tile *) a TileB: (Tile *) b sel : (SEL) sel{
CCAction *actionA = [CCSequence actions:[CCMoveTo actionWithDuration:kMoveTileTime position:[b pixPosition]], [CCCallFuncND actionWithTarget:self selector:sel data: a], nil];
CCAction *actionB = [CCSequence actions:[CCMoveTo actionWithDuration:kMoveTileTime position:[a pixPosition]], [CCCallFuncND actionWithTarget:self selector:sel data: b], nil];
[a.sprite runAction:actionA];
[b.sprite runAction:actionB];
[a trade:b];
moves++;
}
我不确定这是否是正确的方法,或者如何在这里引用该方法:
[self schedule: @selector( ) interval:1.0];
如果有人能提供帮助那就太棒了:)
干杯
答案 0 :(得分:0)
您需要更新标签的内容。您可以让changeWithTileA直接执行此操作,或者您可以使用changeWithTileA调用NSNotificationCenter并使用单独的方法来侦听通知并更新标签的文本。如果您打算在移动计数发生变化时发生其他事情,后者是更好的方法。
进行更新的代码是:
[moveLabel setString:[NSString stringWithFormat:@"Moves: %d", moves]];
但请注意,reference表示setString操作缓慢,建议使用CCLabelAtlas而不是CCLabel。