-SOLVED- So I am using a tut from the game creators for bitmap fonts
it is like this
functions
`=================================
` INITIALISE BITMAP FONTS
`=================================
Function InitialiseBMfonts()
Dim BMchrLeft( 1, 127 )
Dim BMchrWidth( 1, 127 )
Dim BMstringSpriteNo( 1 )
Dim BMstringLength( 1 )
Global NoOfBMfonts
Global BitmapFontImages
Global BitmapFontSprites
BitmapFontImages = 50000
BitmapFontSprites = 50000
`BitmapFontImages/BitmapFontSprites are references to image/sprite numbers used to store
`and display the Bitmap Fonts in your project.
`They can be any number you like but you must ensure that you dont set any other images or
`sprites to use the same numbers that are set aside for Bitmap fonts.
`
`If you only use one set of fonts, then you will have to set aside 100 image numbers
`But you can have as many different fonts as you like, so setting a high number like 50000
`should hopefully ensure that you have enough image numbers set aside before the fonts and
`enough numbers afterwards to include as many fonts as you need.
`The sprite number will increase by one for every character used because each character is
`a seperate sprite
endfunction
`=================================
` LOAD BITMAP FONT
`=================================
Function LoadBMfont(FileName as string )
`The print commands contained in this function are
`meant as only a temporary measure to demonstrate
`what is happening. It is up to you whether or not
`you keep it in your project.
print
print "Loading Bitmap Font : " + FileName
inc NoOfBMfonts
Dim BMchrLeft( NoOfBMfonts, 127 )
Dim BMchrWidth( NoOfBMfonts, 127 )
load image FileName, BitmapFontImages, 1
Print "Cutting Font File ..."
Size = image Width( BitmapFontImages ) / 10
Chr = 32
For y = 0 to 9
for x = 0 to 9
GetImage( BitmapFontImages, Chr + ( NoOfBMfonts * 255 ), x * Size, y * Size, Size, Size )
inc Chr
next x
next y
Delete Image BitmapFontImages
Print "Trimming Font File ..."
TrimBMfont( NoOfBMfonts, Size )
endfunction NoOfBMfonts
`=================================
` GET IMAGE WITH TRANSPARENCY
`=================================
function GetImage( Image1, Image2, Xstart, Ystart, Xsize as dword, Ysize as dword)
`Set up Local variables
Local Width as Dword
Local Height as Dword
Local Depth as Dword
Local Red as Byte
Local Green as Byte
Local Blue as Byte
Local Alpha as Byte
Local Memblock1 as integer
Local NewMemblock as integer
`Find unused memblocks
Memblock1 = 1
repeat
inc Memblock1
until memblock exist( Memblock1 ) = 0
NewMemblock = 2
repeat
inc NewMemblock
until memblock exist( NewMemblock ) = 0
`Do it!
make memblock from image Memblock1, Image1
Width = memblock dword( Memblock1, 0 )
Height = memblock dword( Memblock1, 4 )
Depth = memblock dword( Memblock1, 8 )
make memblock NewMemblock, ( Width * Height ) + 12
Write memblock Dword NewMemblock, 0, Xsize
Write memblock Dword NewMemblock, 4, Ysize
Write memblock Dword NewMemblock, 8, Depth
Position = ( Width * ( Ystart ) * 4) + ( Xstart * 4 ) + 12
NewPosition = 12
for y = 1 to Ysize
for x = 1 to Xsize
Blue = memblock byte( Memblock1, Position + 0 )
Green = memblock byte( Memblock1, Position + 1 )
Red = memblock byte( Memblock1, Position + 2 )
Alpha = memblock byte( Memblock1, Position + 3 )
write memblock byte NewMemblock, NewPosition + 0, Blue
write memblock byte NewMemblock, NewPosition + 1, Green
write memblock byte NewMemblock, NewPosition + 2, Red
write memblock byte NewMemblock, NewPosition + 3, Alpha
inc Position, 4
Inc NewPosition, 4
next x
inc Position , ( Width * 4 ) - ( Xsize * 4 )
next y
`Make the image from the the memblock we have just manipulated
make image from memblock Image2, NewMemblock
`Clean Up
delete memblock Memblock1
delete memblock NewMemblock
endfunction
`=================================
` TRIM BITMAP FONT
`=================================
Function TrimBMFont( FontNo, Size )
`Set up Local variables
Local BlankColumn as integer
Local Alpha as byte
Local Chr as integer
Local Position as integer
Local Memblock1 as integer
`Find unused memblocks
Memblock1 = 1
repeat
inc Memblock1
until memblock exist( Memblock1 ) = 0
`Find the first column of pixels that
`contains a non-transparent pixel
For Chr = 33 to 126
Make Memblock From Image Memblock1, ( FontNo * 255 ) + Chr
for x = 1 to Size
BlankColumn = 1
for y = 1 to Size - 1
if BMchrLeft( FontNo, Chr ) = 0
Position = ( y * Size * 4 ) + ( x * 4 ) + 15
Alpha = memblock byte( Memblock1, Position )
if Alpha > 0
BlankColumn = 0
y = Size - 1
endif
endif
next y
if BlankColumn = 0
BMchrLeft( FontNo, Chr ) = x
x = Size + 1
endif
next x
`Repeat from the right
for x = Size - 1 to 1 step - 1
BlankColumn = 1
for y = 1 to Size - 1
if BMchrWidth( FontNo, Chr ) = 0
Position = ( y * Size * 4 ) + ( x * 4 ) + 15
Alpha = memblock byte( Memblock1, Position )
if Alpha > 0
BlankColumn = 0
y = Size
endif
endif
next y
if BlankColumn = 0
BMchrWidth( FontNo, Chr ) = x - BMchrLeft( FontNo, Chr )
x = 0
endif
next x
delete memblock Memblock1
next Chr
`Set the Space character to display a gap
`that is half the Width of the other characters.
`You can change this to suit your needs but
`I think it works well
BMchrLeft( FontNo, 32 ) = 0
BMchrWidth( FontNo, 32 ) = Size / 2
endfunction
`=================================
` DISPLAY BITMAP FONT
`=================================
Function DrawBMFont( X, Y, S as string, fontStyle, Kern )
inc BMstringSpriteNo( 0 )
ThisString = BMstringSpriteNo( 0 )
SpriteNo = BitmapFontSprites + BMstringSpriteNo( ThisString - 1 ) + 255
dim BMstringSpriteNo( ThisString )
dim BMstringLength( ThisString )
dim BMstringText( ThisString ) as string
dim BMstringStyle( ThisString )
dim BMstringKern( ThisString )
`re-DIMing like this will retain the contents of the array
`whilst causing it to grow. It is a quirk of DBP and most
`BASICs don't work like this but it is a quirk that we can
`take advantage of. You could change the code to use array
`stacks and/or queues but this method works, and I prefer it.
for k = 1 to len( S )
Chr = asc( mid$( S, k ) )
if k = 1
sprite SpriteNo + k, X - BMchrLeft( FontStyle, Chr ), Y, ( FontStyle * 255 ) + Chr
NewX = X + BMchrWidth( FontStyle, Chr ) + Kern
else
sprite SpriteNo + k, NewX - BMchrLeft( FontStyle, Chr ), Y, ( FontStyle * 255 ) + Chr
NewX = NewX + BMchrWidth( FontStyle, Chr ) + Kern
endif
next k
`Store the values for future referencing
BMstringKern( ThisString ) = Kern
BMstringStyle( ThisString ) = fontStyle
BMstringText( ThisString ) = S
BMstringSpriteNo( ThisString ) = SpriteNo
BMstringLength( ThisString ) = len( S )
endfunction ThisString
`=================================
` ALTER BITMAP FONT
`=================================
Function alterBMFont( ThisString, X, Y, S as string, fontStyle, Kern )
SpriteNo = BitmapFontSprites + BMstringSpriteNo( ThisString - 1 ) + 255
`If the altered font is shorter than the previous one
`it will still show the last few characters. So, adding
`the spaces to the end of the string will fix that:)
if len( S ) <> Len( BMstringText( ThisString ) )
for k = Len( S ) + 1 to Len( BMstringText( ThisString ) )
S = S + " "
next k
endif
for k = 1 to len( S )
Chr = asc( mid$( S, k ) )
if k = 1
sprite SpriteNo + k, X - BMchrLeft( FontStyle, Chr ), Y, ( FontStyle * 255 ) + Chr
NewX = X + BMchrWidth( FontStyle, Chr ) + Kern
else
sprite SpriteNo + k, NewX - BMchrLeft( FontStyle, Chr ), Y, ( FontStyle * 255 ) + Chr
NewX = NewX + BMchrWidth( FontStyle, Chr ) + Kern
endif
next k
`Store the values for future referencing
BMstringKern( ThisString ) = Kern
BMstringStyle( ThisString ) = fontStyle
BMstringText( ThisString ) = S
BMstringSpriteNo( ThisString ) = SpriteNo
BMstringLength( ThisString ) = len( S )
endfunction ThisString
`=================================
` DELETE BITMAP FONT
`=================================
Function deleteBMfont( BMid )
First = BMstringSpriteNo( BMid ) + 1
Last = First + BMstringLength( BMid ) - 1
for k = First to Last
delete sprite k
next k
endfunction
`=================================
` HIDE BITMAP FONT
`=================================
Function hideBMfont( BMid )
First = BMstringSpriteNo( BMid ) + 1
Last = First + BMstringLength( BMid ) - 1
for k = First to Last
hide sprite k
next k
endfunction
`=================================
` SHOW BITMAP FONT
`=================================
Function showBMfont( BMid )
First = BMstringSpriteNo( BMid ) + 1
Last = First + BMstringLength( BMid ) - 1
for k = First to Last
show sprite k
next k
endfunction
`=================================
` SIZE BITMAP FONT
`=================================
Function sizeBMfont( BMid, X, Y )
First = BMstringSpriteNo( BMid ) + 1
Last = First + BMstringLength( BMid ) - 1
for k = First to Last
size sprite k, X, Y
next k
endfunction
`=================================
` SCALE BITMAP FONT
`=================================
Function scaleBMfont( BMid, Scale )
First = BMstringSpriteNo( BMid ) + 1
Last = First + BMstringLength( BMid ) - 1
for k = First to Last
scale sprite k, Scale
next k
endfunction
`=================================
` POSITION BITMAP FONT
`=================================
Function positionBMfont( BMid, x, y )
First = BMstringSpriteNo( BMid ) + 1
Last = BMstringLength( BMid ) - 1 + First
S$ = BMstringText( BMid )
fontStyle = BMstringStyle( BMid )
Kern = BMstringKern( BMid )
t = 1
for k = First to Last
Chr = asc( mid$( S$, t ) )
if k = First
sprite k, X - BMchrLeft( fontStyle, Chr ), Y, ( fontStyle * 255 ) + Chr
NewX = X + BMchrWidth( fontStyle, Chr ) + Kern
inc t
else
sprite k, NewX - BMchrLeft( fontStyle, Chr ), Y, ( fontStyle * 255 ) + Chr
NewX = NewX + BMchrWidth( fontStyle, Chr ) + Kern
inc t
endif
next k
endfunction
Then I am creating the text before the loop like this
pressenter = DrawBMFont( 550, 670, "PRESS ENTER", TGC, -3)
Now I am displaying the text as so, but it will not show on the screen because of the array.
for players=201 to 206
playerdistance = Dist(object position x(200) , object position y(200),object position z(200) , object position x(players) ,object position y(players) , object position z(players))
if playerdistance>100 then hideenter=0
if playerdistance<100 then hideenter=1
if hideenter=0 then hideBMfont( pressenter )
if hideenter=1 then showBMfont( pressenter )
next players
But It will show up on screen if only applied to one player like this
playerdistance = Dist(object position x(200) , object position y(200),object position z(200) , object position x(201) ,object position y(201) , object position z(201))
if playerdistance>100 then hideenter=0
if playerdistance<100 then hideenter=1
if hideenter=0 then hideBMfont( pressenter )
if hideenter=1 then showBMfont( pressenter )
Now when I put it into a array like
for players=201 to 206
playerdistance = Dist(object position x(200) , object position y(200),object position z(200) , object position x(players) ,object position y(players) , object position z(players))
if playerdistance>100 then thisObject(players).text1 =0
if playerdistance<100 and thisObject(players).text1 =0 then thisObject(players).text1 =1
if playerdistance<100 and thisObject(players).text1 =1 then showBMfont( pressenter )
if playerdistance>100 and thisObject(players).text1 =0 then hideBMfont( pressenter )
next players
It will not display as it always is hidden, the array will not work , will not display the text, why?