I would like to display a short text phrase along a curve (imagine a semi-circle and then imagine the letters of the text hugging the outline of the semi-circle).
How can text be rendered along a curve with cocos2d?
Thanks, Jay.
A fast, easy to use, free, and community supported 2D game engine
I would like to display a short text phrase along a curve (imagine a semi-circle and then imagine the letters of the text hugging the outline of the semi-circle).
How can text be rendered along a curve with cocos2d?
Thanks, Jay.
I would subclass CCBitmapFontAtlas, then add a custom method that arranges all the children along a curve.
Calculate point on curve, calculate tangent (angle), place letter, repeat for next letter/point.
Calculating the coordinates and tangent of a point on a circle is pretty easy, google around and it shouldn't take you long to do it.
Thank you for the advice. I did end up using a CCBitmapFontAtlas. Because I have a specific case; just fitting text around the static curve of a static graphic object, I was able to create an equation for the circle, and then draw my letters using that equation.
Some psuedo code:
1. I created a CCBitmapFontAtlas with my text string.
2. I looped through each character of the text string using get child by tag (each character becomes its own sprite):
CCSprite *character = (CCSprite *) [label getChildByTag:characterIndex];
3. I adjusted the characters y position using my curve equation.
4. I rotated each character based on its distance from the center of the label. (I estimated the center of the label by dividing the position of the last character by 2.0)
You must log in to post.