使用矢量绘制的数字

发布于 2024-10-31 12:29:44 字数 179 浏览 1 评论 0原文

我想用我自己画的数字来代表一个数字,但不知道如何实现。我如何显示这些数字的整数等值?如果有必要将它们设置为平铺模式,考虑到旧游戏的工作方式,这对我来说很有意义,那么我将使用什么代码在每个游戏之间进行切换?或者还有其他更好的方法吗?另外,我需要该数字能够调整到数字中的位数并从左到右读取(因此十分之一将与十分之一位于同一位置)。感谢您的任何帮助。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

口干舌燥 2024-11-07 12:29:44

您可以轻松使用精灵表。只需将数字从 0 到 9 对齐,并保留一个数组,其中包含精灵上每个数字的位置(a[0] = 0、a[1] = 200、a[2] = 350)然后您将能够检索精灵上数字的位置和宽度,如下所示:

//for 1
xPosition = a[1];
width = a[2]-a[1]; 

您可以使用这两个来绘制蒙版并隐藏精灵的其余部分,以便只有所需的数字可见。这样您只能获得一位数字。然而,将所有这些放在一个类中,并循环遍历您需要的位数。这是如何找出一个数字有多少位的方法:

var value:Number
var digitsNumber:Number =Math.ceil(Math.log(value)/Math.LN10) + 1;

它的值是您的“数字”,例如。 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:

//for 1
xPosition = a[1];
width = a[2]-a[1]; 

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:

var value:Number
var digitsNumber:Number =Math.ceil(Math.log(value)/Math.LN10) + 1;

Where value it's your 'number', eg. 234, 23132 4334 etc

七色彩虹 2024-11-07 12:29:44

通过 switch/case 语句运行这些数字将非常简单。请注意,并不是那么有效,但它肯定会起作用...

private function getCustomInt(targetInt:int):DisplayObject
{
    var graphic:DisplayObject;    
    switch(targetInt)
    {
        case 0:
            graphic = new Zero(); //link to your embedded sprite/ mc /whatever
            break;
        case 1:
            graphic = new One();
            break;
        //etc etc
    }

    return graphic;
}

如果这些是精灵表的一部分,您只需在正确设置了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...

private function getCustomInt(targetInt:int):DisplayObject
{
    var graphic:DisplayObject;    
    switch(targetInt)
    {
        case 0:
            graphic = new Zero(); //link to your embedded sprite/ mc /whatever
            break;
        case 1:
            graphic = new One();
            break;
        //etc etc
    }

    return graphic;
}

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 - - -

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文