To make a sprite of one char from string

有些话、适合烂在心里 提交于 2019-12-11 18:58:43

问题


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");

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';
...

回答1:


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 ; i < str.size() ; i++)
  // here use str[i] as the char you are looking for


来源:https://stackoverflow.com/questions/24227438/to-make-a-sprite-of-one-char-from-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!