Page 1 of 1

Question about the first time call love.graphics.print

Posted: Sat Jul 12, 2014 7:27 am
by yangshenghan
I wonder know what happened when I use love.graphics.print or love.graphics.printf at the first time.

Why the love.graphics.print altered after the first call? Is there anything needed initialized?

Just curious :-)

Code: Select all

local a = love.graphics.print
lg.print('SOME TEXTS', ...) -- Call love.graphics.print first time
local b = love.graphics.print
lg.print('SOME TEXTS', ...) -- Call love.graphics.print second time
local c = love.graphics.print
print(a == b) -- false
print(a == c) -- false
print(b == c) -- true (Why only the first call change love.graphics.print?)

Re: Question about the first time call love.graphics.print

Posted: Sat Jul 12, 2014 9:47 am
by Plu
I think that the first call initializes the default font, but I'm not sure.

Re: Question about the first time call love.graphics.print

Posted: Sat Jul 12, 2014 10:04 am
by bartbes
Indeed, the first time you call print(f) it checks if a font has been loaded, and if not, it loads the default one. As a sidenote, you shouldn't need to tostring the functions to compare them.

Re: Question about the first time call love.graphics.print

Posted: Sat Jul 12, 2014 11:16 am
by yangshenghan
OK. This make sense. But no matter whether I set a font before calling any print function, it changes anyway. So, should I consider this action normal? That is, under any situation, love.graphics.print and love.graphics.printf will change at first call anyway?

By the way, the code is part of my test. I forgot omitting the tostring() function :P