Search code examples
flashactionscript-3integerflash-cs4

Using vector-drawn numbers


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.


Solution

  • 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