# Using vector-drawn numbers

TAGS :
Viewed: 6 - Published at: a few seconds ago

#### [ 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.

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

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