How to use CCLabelTtf?

rene_ruppertrene_ruppert DEXamarin Team, University, XamUProfessors Xamurai

In order to us CCLabelTtf it seems I need XNB fonts or is it supposed to work with TTFs too?
All I get are empty labels. What are the exact steps if I want to use a label with "Arial" TTF?

Best Answer

Answers

  • rene_ruppertrene_ruppert DEXamarin Team, University, XamUProfessors Xamurai
    edited October 2014

    Thanks @Maru‌ - this indeed works but leads to more questions! :-)

    • If CCLabel is for TTF, why is there CCLabelTtf? Found the answer here: https://github.com/mono/CocosSharp/wiki/Labels
    • Do I have to add all the fonts to my fonts folder or can I use the ones that exist on the devices?
    • It seems I can specify any font name - it will fall back to Arial or some kind of system font, correct?

    And additionally: while the code below centers the label perfectly with CCLabelTtf it is all the way to the left with CCLabel. Note: just saw that you seem to have the same problem in your question here.

    var label = new CCLabel ("Bildschirm berühren!", "Arial", 44)
                {
                    Position = this.VisibleBoundsWorldspace.Center,
                    Color = CCColor3B.White,
                    HorizontalAlignment = CCTextAlignment.Center,
                    VerticalAlignment = CCVerticalTextAlignment.Center,
                    AnchorPoint = CCPoint.AnchorMiddle,
                };
    
  • MaruMaru DEMember ✭✭

    @rene_ruppert‌ While I can't help you with your questions, its interesting to see that your CCLabel is all the way to the left while mine is all the way to the right.
    The newest update didn't solved that.

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai
    edited October 2014

    Hey Guys

    Try the following:

                var label = new CCLabel ("Bildschirm berühren!", "Times New Roman", 44)
                {
                    Position = this.VisibleBoundsWorldspace.Center,
                    Color = CCColor3B.Black,
                    IsAntialiased = true,
                    HorizontalAlignment = CCTextAlignment.Center,
                    VerticalAlignment = CCVerticalTextAlignment.Center,
                    IgnoreAnchorPointForPosition = true
                };
    

    Use the IgnoreAnchorPointForPosition = true because you are already setting the position which is Center of the VisbleBoundsWorldspace.

    Let me know if that solves the problem for you. As was noted by Rene this does work differently from the CCLabelTtf and they should be the same. I will open an issue for this to be fixed.

  • MaruMaru DEMember ✭✭

    @kjpou1‌ This is solving this problem, thank you! :)

Sign In or Register to comment.