从字符串制作一个char的sprite [英] To make a sprite of one char from string
本文介绍了从字符串制作一个char的sprite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是训练cocos2d-x。
我试图使用CCLabelBMFont一个字符的精灵。
我写的代码如下
I am just trainning cocos2d-x. I am trying to make a sprite of one char using CCLabelBMFont. I wrote the code as follows
string str = "I like an apple";
CCLabelBMFont *label = CCLabelBMFont::create(str.c_str() , "font.fnt");
我应该如何编写代码以从字符串中创建一个char的精灵。
How should I write the code to make a sprite of one char from string.
这是一种像我这样的感觉。
It is a feeling such as follows that I image.
ex)
CCSprite *spr = 'I';
CCSprite *spr2 = '\n';
CCSprite *spr3 = 'l';
CCSprite *spr4 = 'i';
CCSprite *spr5 = 'k';
CCSprite *spr6 = 'e';
...
推荐答案
A string
是一个数组
的字符,所以任何时候在运行时你可以访问一个 char
,其中
str
是您的字符串变量, x
是char的索引。
A string
is an array
of characters, so any time during run time you can access a single char
of that string using str[x]
, where str
is your string variable and x
is the index of the char.
对于您的代码,您可以使用循环:
For your code you can use a loop :
for (int i = 0 ; str.size() ; i++)
// here use str[i] as the char you are looking for
这篇关于从字符串制作一个char的sprite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文