Sprite Font Spacing Format?

Post » Fri May 19, 2017 5:38 am

Just verifying something: the correct format for doing Sprite Font spacing seems to be:

[[9, "Il"],[10, "i.,'("],[11, ";:!-)[\\/"],[12, "J]<>"],[14, "1"],[15, "j"],[16, "frt*"],[17, "?"],[18, "FLacs_\\"+="],[19, "ESehnz27"],[20, "NPUbdquv358$"],[21, "BCDHZop069"],[22, "Gky4#£"],[23, "KOQRTgx"],[24, "AVX€"],[25, "Y"],[27, "Mw&%"],[30, "m"],[31, "@"],[32, "W"]]

I tried both of the below in the Spacing Data property of the Sprite Font object, however the spacing is not changing, I imagine it's the incorrect format.

{"data": [[9, "Il"],[10, "i.,'("],[11, ";:!-)[\/"],[12, "J]<>"],[14, "1"],[15, "j"],[16, "frt*"],[17, "?"],[18, "FLacs_\"+="],[19, "ESehnz27"],[20, "NPUbdquv358$"],[21, "BCDHZop069"],[22, "Gky4#£"],[23, "KOQRTgx"],[24, "AVX€"],[25, "Y"],[27, "Mw&%"],[30, "m"],[31, "@"],[32, "W"]]}

{""c2array"":true,""size"":[20,2,1],""data"":[[9, ""Il""],[10, ""i.,'(""],[11, "";:!-)[\/""],[12, ""J]<>""],[14, ""1""],[15, ""j""],[16, ""frt*""],[17, ""?""],[18, ""FLacs_\"+=""],[19, ""ESehnz27""],[20, ""NPUbdquv358$""],[21, ""BCDHZop069""],[22, ""Gky4#£""],[23, ""KOQRTgx""],[24, ""AVX€""],[25, ""Y""],[27, ""Mw&%""],[30, ""m""],[31, ""@""],[32, ""W""]]}

i was referring to this blog post for info:
Now there's a new 'Spacing data' property that accepts a JSON array of character widths. This is simply an array of a width in pixels, and a string of the characters with that width. For example [6, "il"] means the characters "i" and "l" will appear at six pixels wide instead of the default character width.

https://www.scirra.com/blog/203/some-bo ... onstruct-3
B
56
S
25
G
19
Posts: 173
Reputation: 14,083

Post » Fri May 19, 2017 6:12 am

The top example is correct. It does work. If I create a default spritefont and use this data, the spacing does change (it's wrong of course), but it does change.
ImageImageImage
B
71
S
22
G
274
Posts: 3,828
Reputation: 151,299

Post » Fri May 19, 2017 6:02 pm

Thanks, experimenting with an appropriate font and it looks it now works.

I hope folks update their assets to include this, would be even better if it could be embedded in the font data itself. Then the spacing could be loaded automatically. I wonder if there is enough space in PNG metadata to include a long string like this.

@Ashley thoughts?
B
56
S
25
G
19
Posts: 173
Reputation: 14,083

Post » Mon Feb 12, 2018 7:10 pm

sorry to resurrect this old post.. what is the default font that SpriteFont uses? and why isn't there Spacing data already defaulted for it?

How can get Spacing data for the default SpriteFont font?
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016

Post » Mon Feb 12, 2018 9:09 pm

The default font is mono-spaced, so there is no width data required - it's all the same: 16. It's really not a good example for the spacing feature.

This will generate the data for you.
viewtopic.php?f=157&t=86546
ImageImageImage
B
71
S
22
G
274
Posts: 3,828
Reputation: 151,299

Post » Mon Feb 12, 2018 10:26 pm

blackhornet wrote:The default font is mono-spaced, so there is no width data required - it's all the same: 16. It's really not a good example for the spacing feature.



well, it's supposed to be, but it's not really. Capital 'I', 'T' and many others are not correctly aligned. I guess it's just a not-so-great font sprite.

I'm teaching a class, and want to start them with SpriteFont instead of the Text object, but that's proving difficult since the default sprite font is not very aesthetically pleasing. And while the GiveYourFontsMonoSpace program is excellent, the workflow is a little too cumbersome for my students.
B
101
S
34
G
16
Posts: 1,212
Reputation: 17,016


Return to General Discussion

Who is online

Users browsing this forum: unforseen and 1 guest