使用矢量绘制的数字
我想用我自己画的数字来代表一个数字,但不知道如何实现。我如何显示这些数字的整数等值?如果有必要将它们设置为平铺模式,考虑到旧游戏的工作方式,这对我来说很有意义,那么我将使用什么代码在每个游戏之间进行切换?或者还有其他更好的方法吗?另外,我需要该数字能够调整到数字中的位数并从左到右读取(因此十分之一将与十分之一位于同一位置)。感谢您的任何帮助。
I want to use numbers I've drawn myself to represent a number, but don't know how to implement this. How would I display the equivalent of an integer with these numbers? If it's necessary to have them in a tile pattern, which makes sense to me considering how older games worked, then what code would I use to switch between each? Or is there another, better way? Also, I need the number to be able to adjust to the number of digits in the number and read from left to right (so the 1 in 10 would be in the same place as the 1 in 1). Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以轻松使用精灵表。只需将数字从 0 到 9 对齐,并保留一个数组,其中包含精灵上每个数字的位置(
a[0] = 0、a[1] = 200、a[2] = 350
)然后您将能够检索精灵上数字的位置和宽度,如下所示:您可以使用这两个来绘制蒙版并隐藏精灵的其余部分,以便只有所需的数字可见。这样您只能获得一位数字。然而,将所有这些放在一个类中,并循环遍历您需要的位数。这是如何找出一个数字有多少位的方法:
它的值是您的“数字”,例如。 234、23132 4334 等
You can easily use a sprite sheet. Just align your digits from 0 to 9 on it and keep an array with the position of each digit on the sprite (
a[0] = 0, a[1] = 200, a[2] = 350
) then you will be able to retrieve the position and the width of the digit on the sprite like this:You can use this two to draw a mask and hide the rest of the sprite so only the needed digit it's visible. You obtain this way only one digit. However put all this in a class and make a loop over the number of digits you need. This is how you find out how many digits does a number have:
Where value it's your 'number', eg. 234, 23132 4334 etc
通过 switch/case 语句运行这些数字将非常简单。请注意,并不是那么有效,但它肯定会起作用...
如果这些是精灵表的一部分,您只需在正确设置了scrollRect的父图形中设置子图形的位置即可。反正。有很多方法可以做到这一点 - 这就是一个 - - -
It would be pretty straightforward to run these digits through a switch/case statement. Not all that efficient, mind you, but it would certainly work...
If these were part of a sprite sheet, you could just set the position of a child graphic in a parent that had scrollRect properly set up. Anyway. Bunch of ways to do this - and that'd be one - - -