Text Object and Bitmap fonts?


(George Kurelic) #1

I’m really surprised This isn’t requested more. I’m planning my UI and there’s a large dynamic text box that will be populated with high scores. I would like to be able put a text box in tiled, pointing at a tileset of letters to be used for a bitmap font. then I can put placeholder text to see if I like the alignment.

What I’m doing now is putting a rectangle object with image, tiling and alignment instructions in the custom properties. then I run the game, see if it lines up right, nudge it in Tiled, and repeat. I’m glad this is the only dynamic text I’m dealing with, otherwise this would be a huge pain


Development Updates
(Thorbjørn Lindeijer) #2

I definitely agree there should be a text object. There’s several people who have requested this already actually, but I just haven’t gotten around to it:

niedzielski even posted a bounty on the issue, so if nobody else does it I will make sure to get to it soon, and I’ve added it to the Tiled 1.0 milestone.

Supporting bitmap fonts based on tilesets is an interesting idea, though I’m not sure if it’s the easiest approach. Usually the letters are not all the same size, so either tilesets will need to support this (it should be supported eventually anyway) or each letter would need to be its own image. There’s also the fact that you’d need to assign a property to each tile telling Tiled what character it represents. I think there are probably already common ways of dealing with bitmap fonts, and then it would make sense to support that more directly in Tiled. What format is your font in?

In any case bitmap font support is definitely a larger issue than supporting a text object based on system fonts.


(George Kurelic) #3

I can start looking into it, starting with a normal system font.

In terms of exporting a field using bitmap font, I expect it being not that different from the properties of a normal textfield object, except it would point to a bitmap font definition, which is similar to a tileset but with optional kerning properties per character. Most bitmap fonts in editors/engines assume monospace, so kerning could come later.

For instance a bitmap font def would have a source image, tile width/height, margin, spacing, and a list of characters in the image from topleft to bottom right

name: "numbers_small"
image:
tileWidth: 8
tileHeight: 10
characters: “0123456789”

and the textfield object might just list numbers_small in the font drop down, or there’s a radio button to select bitmap font over system font which affects the dropdown contents


(Thorbjørn Lindeijer) #4

@Geokureli Did you notice I’ve implemented the first version of the new Text object this week? You can check it out using a development snapshot build.

Currently it only supports rendering using system fonts, so I could rely on the Qt font rendering support, including text wrapping and alignment. Of course it would still be nice to extend this to also support bitmap fonts eventually, as well as to allow referring to some TTF file directly.


(George Kurelic) #5

Thanks for the heads up, I’ll be sure to check it out!


(Irgendwer A8) #6

Supporting bitmap fonts based on tilesets is an interesting idea, though I’m not sure if it’s the easiest approach.

That’s exactly what I’m looking for! I design game screens for vintage computers and my tiles are (redefined) char sets. Now adding labels to such screens is a very tedious work, while selecting and placing chars one by one.
My feature wish would be setting a base char for a tile (like assigning an ‘A’ to my tile which looks like an ‘A’) and when typing, the ASCII codes will select the matching tile offsetting to the base I’ve applied and put them into the map cells accordingly.
This way I would also be able to just apply the base ‘0’ to my ‘0’ looking tile and are able to type only numbers, while all other tiles have a different meaning and are not meant to be typed.

(The only thing missing would be a binary export of maps then, but this is a different story.)

I guess a bounty would help…?


(Irgendwer A8) #7

Found the time to implement as least a prototype.
I won’t create a pull-request as these are my first steps with QT and far from being worth an integration in the current state. Unfortunately I’m currently not in the position to continue the work, so how much do you need to create a functionality like illustrated? (The first combo box selects a mapping file containing a char-index to tile-index table.)


(Irgendwer A8) #8

Not comments at all? Nobody else has the need for a “Label Brush”?


(Thorbjørn Lindeijer) #9

Hey @IrgendwerA8, sorry for not responding to this earlier. I think it’s awesome what you have done here, especially without previous Qt knowledge! I would encourage you to open a pull request anyway, so that the work will also be available for others and I could review your code. Maybe in the future you will have time to continue work on it, or somebody else could continue it.

That said, I do think this will be a very rarely needed feature. I recognize that when you need it, you can’t really do without it, but I would prefer this feature to be opt-in somehow to avoid cluttering the UI for those who never need it. That’s something I’d be glad to work on though.

Finally, I’m currently working on making Tiled scriptable, and being able to write custom tools is part of that. I will try to make sure that such a tool could be written in a script. That way it would be easier to develop since you don’t need a Qt/C++ development environment, and it will be easier to share the tool once written.


(Irgendwer A8) #10

Thanks for the reply.
I’ll try to find the time to provide at least the basic label brush mechanism with ASCII mapping for a PR.
And yes, you are right: If designing screens with (tile-)labels there is no “not-tedious alternative” currently in Tiled.
Looking forward for your scripting mechanism - that’s indeed a very welcomed addition!