使用 XNA 设置 C# 中文本的格式
我目前正在尝试使用 XNA 为我的 GUI 制作一个文本框,我想知道如何在字符串中找到标记的文本。
例如我有这种文本:
Hey there, I was <r>going to</r> the <b>Mall</b> today!
因此
标记将表示红色文本, 标记将表示蓝色文本。
我想确切地知道红色文本从哪里开始以及蓝色文本从哪里开始,以便我可以单独渲染它们。
您有什么建议可以做什么,以及使用什么来做到这一点?
提前致谢。
I'm currently trying to make a TextBox for my GUI with XNA, and I was wondering how could I find tagged text in a string.
For instanceI have this kind of text:
Hey there, I was <r>going to</r> the <b>Mall</b> today!
So the <r>
tag would represent red text and the <b>
tag would represent blue text.
And I want to know exactly where the red text starts and where the blue text starts so I could render them separately.
Do you have any suggestion what to do about it, and what to use for doing that?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议使用两种方法来执行此操作
首先,有一个可以获取字符串并返回字符串颜色对集合的方法:
然后您需要一个如下所示的绘制方法:
I would suggest doing this with two methods
First, have a method that can take your string and return a collection of string color pairs:
Then you would need a draw method like this:
好吧,您可以解析该行,当您达到文本的颜色属性设置时,它现在将呈现蓝色,但它必须是单独的渲染调用,否则整个字符串将变成蓝色。因此,如果您在遇到标签时创建一个新字符串,然后设置颜色属性,然后渲染该字符串,那么这应该可以工作。
Well you could just parse the line and when you reach a set a color property of your text so that it will now render blue but it will have to be a separate render call or else the whole string will turn blue. So if you make a new string when you come upon a tag then set the color property then render that string then that should work.