![]() |
Draw bitmap numbers
1 Attachment(s)
Made these simple functions to display numbers as images instead of text. Details such as these can make a lot of difference in presentation :)
PHP Code:
DrawNumber: This is the simple function. What it does is display numbers using state.png. Thus, it is limited to the characters defined in that, "0123456789/:" and spaces. If you'd like, you could simply take this function and customize the variables defined in it. Parameters are: DrawNumber(index,text,x,y[,center?]); Index is the starting index to display the images. text is what you wish to display. I recommend sending it as a string to assure gscript doesn't mess up the values. And the last parameter is whether you want the text centered on the x-position or not. You can omit this if you'd like, and it just won't center it. An example of using it: DrawNumber(200,"0123 456",20,150); DrawNumber(200,player.mp,20,150,true); DrawNumber(200,03242,20,150); DrawCustomNumbers: This is the complicated version. This lets you define all the parameters so that you can use a customized image instead of state.png. The parameters are: DrawNumber(index,text,x,y,charactermap,partx,party ,partw,parth,spacing[,center?]); The character map is the layout of all the characters as they are in the image. This must be a string. For example, the character map for state.png is "0123456789/:". Partx/y/h/w should be fairly self-explanatory. These will define the startx/y of the number map in an image(typically 0,0 but may be different if in a gui template). Partw/h define the width and height of the characters. As precautionary, these will default to 16,16 if they are not defined. Lastly is the spacing. This will offset the space between the images when they are drawn. Example of usage: DrawCustomNumbers(200,draw,20,150,"dusty_defaultnu mbers.png","0123456789/:.",0,0,14,16,3,true); Oh yes, and both functions already account for spaces. You do not need to account for them in your character maps. edit: obligatory screenshot attached. Also, I may eventually add the ability to perhaps center the text... |
I like that, any chance of get functions for the width and height? I imagine those will come if you make the center function though.
|
Quote:
|
I meant.. getStateTextWidth(text) + getStateTextHeight(text)
|
Quote:
text = "012345"; DrawNumber(index,text,x + DrawCenter(text),y); |
Okay, I've updated it and just added a parameter for centering. Also fixed a major bug where it wasn't hiding left-over images after being updated.
|
Not bad, not bad at all.
|
| All times are GMT +2. The time now is 12:45 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.