iPhone cocos2d游戏中的文字输入效果

时间:2009-10-21 10:21:08

标签: iphone text cocos2d-iphone effect

在很多游戏中,当一个角色说话时(对话),文字有一个打字效果,看起来你正在看着文字的字符类型。

对于使用cocos2d的iPhone游戏,实现这种外观和(简单)“动画”的好方法是什么?

如果有一种方法可以使用cocos2d,这很好,但我并不完全反对在cocos2d的EAGL(OpenGL ES)视图之上分层UIView子类(UILabel?)。

3 个答案:

答案 0 :(得分:2)

我最终使用了内置的UIKit元素(UILabel)并将它们作为子视图添加到窗口中。

答案 1 :(得分:1)

内置UIKit无法与cocos2d-built-in UIKit一起使用,例如CCLabel,CCSprite

答案 2 :(得分:0)

我建议使用CCLabelTTFCCAction,如下所示:

- (void) typeText
{
    static NSUInteger currentCharacter = 0;

    // Your instance variable stores the text you want to "type" in it:
    _text;

    // Sorry, I can't remember substring functions, this is pseudo-code:
    NSString *substring = [_text getSubstringFrom:0 to:currentCharacter];

    // Also can't remember how to get length of a string (yipes)
    NSUInteger stringLength = [_text length];

    if (currentCharacter < stringLength)
    {
        CCSequence *loop = [CCSequence actions:[CCDelayTime actionWithDuration:0.3f],[CCCallFunc actionWithTarget:self selector:@selector(typeText)],nil];
        [self runAction:loop];
    }
}

这是未经测试的代码。此外,它假定typeText函数在CCNode的子类中实现,因为它调用[self runAction:]