1

在许多游戏中,当角色说话(对话)时,文本具有打字效果,看起来您正在观看角色键入文本。

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

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

4

3 回答 3

2

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

于 2009-11-14T11:07:24.073 回答
1

内置UIKit不能很好地与cocos2d-built-in UIKit,如CCLabel,CCSprite.

于 2010-05-11T03:52:23.683 回答
0

我建议使用 aCCLabelTTFCCAction如下:

- (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:]

于 2012-03-30T17:04:08.940 回答