Need help setting a SpriteFont text.

  • Hey all, I tried searching for this topic in the forums, so I apologize if I missed it, but I've run into some trouble, and I'm hoping someone can throw me an answer.

    I'm trying to create a character screen for a player that reflects its stats.

    I have a dictionary called "PlayerAttributes" with an instance variable called "Strength" and I created a SpriteFont which I want to display the current Strength value. What I tried doing was putting in:

    Every tick - set SpriteFont text : PlayerAttributes.Strength

    in my event sheet, but it doesn't work. Is it possible to set a textbox, or spritefont's text to a numerical instance variable, or does it have to be a string?

    Hope my question is understandable. Please help!

    Thanks.

    -BabyCave

  • That should be fine. Is your object big enough to show the full value?

    Does your character set show all characters?

  • Hurr durr.

    I just realized I didn't have the layout assigned to the correct event sheet.

    Thanks for telling me the event should be okay!!

  • Hi baby

    Consider using Sprite font+ Plugin.If you are using sprite fonts often,You may find it difficult that during runtime and editing time, fonts are rendered differently if you assign custom character widths in the event sheet.

  • Hey Doc,

    I'll definitely look into that. Thanks!

  • blackhornet,

    I just noticed your comment about not all the characters in the set showing. I am trying to create a completely custom character set, but only about half of them show at runtime. Is this because the widths are set incorrectly?

    I am using GiveYourFontsMono, and all characters are showing there, but some are missing at runtime.

  • Have you copied the set exactly from my app to C2, and implemented the width code from the sample with the data in the TXT file generated with the image?

  • I stole your sample and added a bunch of new characters as shown below:

    [attachment=1:1pbe1dou][/attachment:1pbe1dou]

    When I run the .capx above, some of the characters don't show up at all. My initial thought was that Spritefont can only handle characters in a very limited character set. For example, ? (T) shows up just fine within the text plugin, but not at all as a spritefont.

  • [attachment=0:1yhbjxnp][/attachment:1yhbjxnp]

    This is what is displaying. Note the lack of the ? character in the spritefont, and the big gap between the capital "I" and the capital "J".

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Can you post the CAPX?

  • [attachment=0:2gvk959a][/attachment:2gvk959a]

    Here's the .capx. Thank you so much for your help on this!

  • You didn't set the 'Character set' of the SpriteFont. It must match.

  • blackhornet, You are a genius. Thank you!

    On a side note, I am looking to recreate superscripts and subscripts within a spritefont. Would it be possible to remap the higher character codes to glyphs that correspond to subscripts and superscripts of the standard alphabet? It seems like this should work just as long as there are at least (26 letters x 2 + 10 digits) = 62 unused character codes available to be remapped.

  • It will take some manual work, but I don't see why that wouldn't work.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)