Android 中的自定义字体 - 简单而便宜的方法
我正在制作一款 Android 游戏,我想为得分计数器使用自定义字体。
1)据我所知,我可以使用 ttf 文件轻松实现自定义字体,但创建 ttf 文件需要昂贵的程序。
2)由于它主要是数字,因此只有十张图像,也许我可以自己实现。为此,是否有一种方法可以接受 int 并返回数字的一部分,例如 String.substring() ?或者将数字转换为字符串然后解析出各个数字会更简单吗?
3)我还没有考虑过的可能性?
I'm making an Android game, and I want to use a custom font for the score counter.
1) From what I've found I can use a ttf file to easily implement a custom font, but creating a ttf file requires an expensive program.
2) Since it's mainly numbers, and thus only ten images, maybe I can implement it myself. For that, is there a method that can take an int and return a portion of the number, like String.substring()? Or would it be simpler to just transform the number into a string and then parse out the individual numbers?
3) A possibility I haven't considered yet?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
1)有一些工具 在线免费创建字体,但他们可能无法提供对您正在寻找的字体的控制。在我链接的文章中提到的两个中,FontStruct 似乎更简单、更直观,而 FontForge 似乎更强大。如果其中之一能满足您的需求,我想它比处理 10 个单独的图像更不会占用资源。
2)你绝对可以实现这个。 Strings 和 CharSequences 都有 charAt(int index) 函数,允许您访问单个字符。您可以使用循环来测试每个单独的字符并显示适当的图像。 String.substring(start, end) 确实返回原始字符串的一部分,但我不确定这对您有什么帮助。
1) There are some tools online to create fonts for free, but they might not provide the control over your font that you are looking for. Of the two mentioned in the article I linked to, FontStruct seems simpler and more intuitive, while FontForge seems more powerful. If one of these suits your needs, I imagine it would be less of a resource hog than dealing with 10 individual images.
2) You could definitely implement this. Both Strings and CharSequences have charAt(int index) functions that allow you to access the individual characters. You could use a loop to test each individual character and show the appropriate image. String.substring(start, end) does return a portion of the original string, but I'm unsure of how that would help you.