Reputation: 241
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';
...
Upvotes: 0
Views: 266
Reputation: 7466
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
Upvotes: 1