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

发布于 2024-08-08 15:37:40 字数 207 浏览 2 评论 0原文

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

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

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

In many games, when a character is speaking (dialogue), the text has a typing effect, where it looks like you are watching the character type the text.

What would be a good way to achieve this look and (simple) "animation" for an iPhone game which uses cocos2d?

It's good if there's a way to do it with cocos2d, but I'm not completely opposed to layering a UIView subclass (UILabel?) on top of cocos2d's EAGL (OpenGL ES) view.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

傲影 2024-08-15 15:37:40

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

I ended up using built-in UIKit elements (UILabel) and adding them as subviews to the window.

余生共白头 2024-08-15 15:37:40

内置的 UIKit 无法与 cocos2d-built-in UIKit 很好地配合,例如 CCLabel、CCSprite

the built-in UIKit could not works well with cocos2d-built-in UIKit,such as CCLabel,CCSprite.

习ぎ惯性依靠 2024-08-15 15:37:40

我建议使用 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:]

I would suggest using a CCLabelTTF and CCAction as follows:

- (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];
    }
}

This is untested code. Also, it assumes that the typeText function is implemented in a subclass of CCNode because it calls [self runAction:]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文