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
63
S
28
G
19
Posts: 190
Reputation: 14,592

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
72
S
22
G
290
Posts: 3,886
Reputation: 159,513

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
63
S
28
G
19
Posts: 190
Reputation: 14,592

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
103
S
35
G
16
Posts: 1,244
Reputation: 17,240

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
72
S
22
G
290
Posts: 3,886
Reputation: 159,513

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
103
S
35
G
16
Posts: 1,244
Reputation: 17,240

Post » Sat Apr 14, 2018 6:00 am

Did people successfully get C3 spacing data to work or do we need to go back to using arrays to arrange spacing?

Pasting something like this into the Spacing Data field doesn't seem to work:
[[9,"l:.0"],[10,1ijtI"],[12,"f"],[14,"23456789abcdeghkmnopqrsuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ"]]
Football Dash (1m+): GooglePlay | AppStore

Zombie Bash: GooglePlay | AppStore

www.lumicreative.com
B
82
S
31
G
8
Posts: 506
Reputation: 10,739

Post » Sat Apr 14, 2018 2:12 pm

You missed a quote in the '10' section. It works if you fix it.
ImageImageImage
B
72
S
22
G
290
Posts: 3,886
Reputation: 159,513

Post » Sun Apr 15, 2018 11:12 pm

@blackhornet You're right. That did the trick! Can't believe I missed that.
Football Dash (1m+): GooglePlay | AppStore

Zombie Bash: GooglePlay | AppStore

www.lumicreative.com
B
82
S
31
G
8
Posts: 506
Reputation: 10,739


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest