Problem overriding love.graphics.print

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Simtex
Prole
Posts: 39
Joined: Sun Dec 14, 2008 5:31 am

Problem overriding love.graphics.print

Post by Simtex »

This scales properly:

Code: Select all

love.graphics.oldPrint = love.graphics.print

function love.draw()
	love.graphics.scale(2, 2)
	love.graphics.print("Hardcore LOVE", 1, 1)
end

function love.graphics.print(text, x, y)
	love.graphics.oldPrint(text, x, y)
end
This doesn't (only the position of love.graphics.scale has changed):

Code: Select all

love.graphics.oldPrint = love.graphics.print

function love.draw()
	love.graphics.print("Hardcore LOVE", 1, 1)
end

function love.graphics.print(text, x, y)
	love.graphics.scale(2, 2)
	love.graphics.oldPrint(text, x, y)
end
Why?
User avatar
crow
Party member
Posts: 186
Joined: Thu Feb 24, 2011 11:47 pm
Location: UK
Contact:

Re: Problem overriding love.graphics.print

Post by crow »

This might sound silly but try putting the print function before draw this might be wrong but I had a problem just link this in a standard lua function when calling functions like you are maybe it will work maybe not but at lest its a try ?
Sir Kittenface
Möko IDE Codename (Erös) Returns Soon

I am dyslexic so if any of my replys confusing please just ask me to reword it as this will make things a lot easier for all parties lol.
User avatar
Simtex
Prole
Posts: 39
Joined: Sun Dec 14, 2008 5:31 am

Re: Problem overriding love.graphics.print

Post by Simtex »

crow wrote:This might sound silly but try putting the print function before draw this might be wrong but I had a problem just link this in a standard lua function when calling functions like you are maybe it will work maybe not but at lest its a try ?
Yeah I messed around with positioning a bit myself, it doesn't seem to help.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Problem overriding love.graphics.print

Post by BlackBulletIV »

crow wrote:This might sound silly but try putting the print function before draw this might be wrong but I had a problem just link this in a standard lua function when calling functions like you are maybe it will work maybe not but at lest its a try ?
This shouldn't be a problem, Lua doesn't statically find functions like C/C++. If it's in the global namespace when called, it's all good.

I'm not really sure why it's not working, although I think should only need to call love.graphics.scale once, in love.load or something. But, I might be wrong.
User avatar
Simtex
Prole
Posts: 39
Joined: Sun Dec 14, 2008 5:31 am

Re: Problem overriding love.graphics.print

Post by Simtex »

BlackBulletIV wrote: I think should only need to call love.graphics.scale once, in love.load or something. But, I might be wrong.
Scale & translate both only last until love.draw() exits, so you have to call them every time you call love.draw().
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Problem overriding love.graphics.print

Post by Robin »

BlackBulletIV wrote:I'm not really sure why it's not working, although I think should only need to call love.graphics.scale once, in love.load or something. But, I might be wrong.
You are, in fact, wrong. You need to do it every frame before drawing the things you want scaled (also: look at love.graphics.push and -pop).

Not sure why the code in the OP doesn't work. I would suggest not to redefine any API functions, which will probably only lead to people crying and being confused. ;)
Help us help you: attach a .love.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Problem overriding love.graphics.print

Post by BlackBulletIV »

Oh ok, I was wrong then. I guess that's why my Camera class wouldn't work unless I activated it every frame.
User avatar
EmmanuelOga
Citizen
Posts: 56
Joined: Thu Apr 22, 2010 9:42 pm
Location: Buenos Aires, Argentina
Contact:

Re: Problem overriding love.graphics.print

Post by EmmanuelOga »

This is way it does not work:

https://bitbucket.org/rude/love/src/13f ... ua#cl-1268

Try:

Code: Select all

love.graphics.oldPrint = love.graphics.print1
function love.graphics.print1(...)
   love.graphics.scale(2, 2)
   love.graphics.oldPrint(...)
end

function love.draw()
   love.graphics.print("Hardcore LOVE", 1, 1)
end
That's an horrible idea though. I would not recommend doing that. If you need that extra functionality, just add a new function. You don't even need to define it inside the love.graphics namespace.
Robin wrote:I would suggest not to redefine any API functions
I agree.
--------------------------------------------------------------------------------------------------------
http://EmmanuelOga.com
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: Problem overriding love.graphics.print

Post by BlackBulletIV »

Looking at that, I think you might need to call love.graphics.print once, and then redefine it (or, you could use the method shown above of course). That'll probably work. But as said, it's not a good idea to go hacking around with the Love internals like that.
User avatar
Simtex
Prole
Posts: 39
Joined: Sun Dec 14, 2008 5:31 am

Re: Problem overriding love.graphics.print

Post by Simtex »

EmmanuelOga wrote: That's an horrible idea though. I would not recommend doing that. If you need that extra functionality, just add a new function. You don't even need to define it inside the love.graphics namespace.
Robin wrote:I would suggest not to redefine any API functions
I agree.
Well that is certainly interesting. I wonder why they did it that way, thanks for your answer though.

I understand overriding the API is usually a bad idea, but there's a very specific reason I'm doing this and it's important for testing without having to rewrite a bunch of code.

Thanks again.
Post Reply

Who is online

Users browsing this forum: Google [Bot], PotatoDude and 199 guests