xcode Cocos2D:编写文本并从文本字段获取输入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4140028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:54:35  来源:igfitidea点击:

Cocos2D: Writing Text and getting input from a text field

xcodetextcocos2d-iphonefield

提问by Angelo Rivera

Hi I'm having a hard time figuring how to just display simple text in a Cocos2D game.

嗨,我很难弄清楚如何在 Cocos2D 游戏中只显示简单的文本。

I know how to write code to show pictures and to change the current picture but that's it. Can anyone help me with this?

我知道如何编写代码来显示图片和更改当前图片,但仅此而已。谁能帮我这个?

Also I know making a text field requires UITextField but where exactly would I implement the code for that? I have classes the store how to start the game up and to create the pictures/display but that's it.

我也知道制作一个文本字段需要 UITextField 但是我到底应该在哪里实现代码?我在商店里教了如何启动游戏和创建图片/显示,但就是这样。

Thanks for the help.

谢谢您的帮助。

回答by Martin

You can easily display text with CCLabel Take a look at the documentation for it. You'll see lots of warnings, though, that it's slow if you plan on update frequently (say, it's the players current score or a timer). Then you'll want to look into CCLabelAtlas.

您可以使用 CCLabel 轻松显示文本 看看它的文档。但是,您会看到很多警告,如果您计划频繁更新(例如,这是玩家当前的分数或计时器),它会很慢。然后你会想要研究 CCLabelAtlas。

You can add UITextField, and other UIKit elements to your game by using a wrapper. I'm partial to UIViewWrapper but there are probably other solutions. http://www.cocos2d-iphone.org/forum/topic/6889

您可以使用包装器将 UITextField 和其他 UIKit 元素添加到您的游戏中。我偏爱 UIViewWrapper,但可能还有其他解决方案。http://www.cocos2d-iphone.org/forum/topic/6889