如何在标签上为插槽机器上的文本设置动画?

时间:2013-03-02 14:11:51

标签: cocos2d-iphone bitmap-fonts cclabelttf

我想在标签text.i上执行动画,需要在标签上显示10。标签应首先显示0,然后显示1,2,3 ....以10开头。

示例:显示显示编号动画似乎在插槽轮中。

我该怎么做?是在科科斯2d的任何技巧?

有人知道怎么做吗?

1 个答案:

答案 0 :(得分:0)

首先将标签设置为实例变量。

// In your .h
CCTabelTTF *_myLabeL;

然后(假设您已经在项目中添加了它)为它创建一个更新方法

- (void)updateLabel {
    int currentVal = [_myLabel intValue];
    NSString *newString;

    currentVal += 1;
    newString = [NSString stringWithFormat:@"%i", currentVal];

    [_myLabel setString:newString];
}

现在我们可以创建一个方法来调用您的更新:

- (void)startUpdatingLabel:(int)newValue {
    int curVal = [_myLabel intValue];
    int difference = newValue-curVal;
    for(int i=0; i > difference; i++) {
        [self performSelector:@select(updateLabel) withObject:nil afterDelay:1.0];
    }
}

然后,只要你想更新标签(比如说10),你所要做的就是调用

[self startUpdatingLabel:10];

它会每1秒更新一次标签,直到达到新值