News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

making fonts global

Started by andrik, January 18, 2007, 02:27:24 PM

Previous topic - Next topic

andrik

Hi,

Maybe a stupid question, but is there a way to make loaded fonts global?
So for instance at the start of my program I use the following statement:
loadfont "comic sans MS",2,18,0


Now when I enter a function and I try to set the font with:
setfont 2, nothing happens.
when I put the loadfont in front of the setfont, it works, but I want to load a font only once.

So is there a way to make it global?

thanks in advance,
Andrik

kevin

#1
 Fonts are global, scope has no effect on them.  You can't however change to a font that doesn't exist.    

ie.
PlayBASIC Code: [Select]
 Setfont 2   <-------- You can't do this, as font 2 doesn't exist !  PB will restore the deault font. Font #1
Loadfont fielname$,2, etc



solution.

PlayBASIC Code: [Select]
   Loadfont Filename$,2, ETC
Loadfont Filename$,3, ETC
Loadfont Filename$,4, ETC
ETC ETC

Sentfont 2

print stuff

SetFont 5

print stuff




andrik

Kevin,

I'm not sure that I follow...
As I wrote in my first post, In my main program, I load a font with
loadfont "<fontname>",2,16,0
So the font is loaded at index 2.
and the font exists by the way...I tried.

Now when I try to set the font in a function (which resides in the same .pba) with setfont 2, it defaults to 1.
You say fontloading is global, this means I have to load them only once, right?

Only when I load the font again inside the function, do I see the actual font.

best regards,
andrik

Ian Price

I don't know exactly what you're doing, but this function jump certainly proves Kevin to be correct.


LoadFont "comic sans MS",2,18,0

while not esckey()

setfont 1
text 10,10,"HELLO!"

SetFont 2
text 10,20,"HELLO!"

sync
cls 0

text 10,40,"PRESS SPACE TO JUMP TO NEW FUNCTION"

if spacekey() then main()

endwhile
end


; Main
function main()

while not esckey()

setfont 2

text 10,10,"THIS IS STILL COMIC SANS FONT"

sync

cls 0

endwhile

endfunction


Pressing SPACE jumps from the loop to the Main function, without loading the font again and shows that the font is still Comic Sans.
I came. I saw. I played some Nintendo.

andrik

Apparently I'm doing something wrong here...

Thanks for the code example, I'll try again tonight when I'm at home.
It's probably an oversight on my part somewhere in my code.

thanks!

andrik

Oops!

My mistake, I found another loadfont statement in my program, which loaded to the same index.

thanks for the help!

Andrik

Ian Price

I came. I saw. I played some Nintendo.