love.graphics.translate & printf

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.
Post Reply
luminosity
Prole
Posts: 34
Joined: Fri Sep 24, 2010 5:46 am

love.graphics.translate & printf

Post by luminosity »

Hi,

apologies if this is already known, I skimmed search results for translate and found nothing, so. I'm trying to add resolution support to my game. The backgrounds and gui are all designed for 1024x768, so my current plan is for higher resolutions to just be a bit lazy and add bars around the content, centreing everything in the middle. This seems to work well except.. the first time printf is called it behaves rather oddly. The first character of the string is printed in the correct place, the rest is then printed in the top left corner or completely off screen. All subsequent drawing is reverted back to the original co ordinates before I called translate.

Is this a known problem with a workaround / fix in the works?

Thanks guys.
Attachments
love-translate-printf.png
love-translate-printf.png (254.98 KiB) Viewed 1340 times
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: love.graphics.translate & printf

Post by kikito »

Please upload a .love file so we can test.
Last edited by kikito on Fri Sep 02, 2011 3:19 pm, edited 1 time in total.
When I write def I mean function.
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: love.graphics.translate & printf

Post by miko »

luminosity wrote:Hi,
Is this a known problem with a workaround / fix in the works?
For me, it looks like a bug in you code. So yes, upload your *.love file, then the fix will be in the works.
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
luminosity
Prole
Posts: 34
Joined: Fri Sep 24, 2010 5:46 am

Re: love.graphics.translate & printf

Post by luminosity »

I'm not sure how it could be a bug in my code though, you can see the rendering changes midway through a printf, and the "ontinue" from that string has disappeared completely. I didn't upload a .love vecause my game is nearing completion, and I don't want it sitting on a public forum particularly -- not till it's out for sale. However it seems like this isn't a known bug? I'll try reproducing it in a smaller example file.

Thanks,
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: love.graphics.translate & printf

Post by TechnoCat »

luminosity wrote:I'm not sure how it could be a bug in my code though, you can see the rendering changes midway through a printf, and the "ontinue" from that string has disappeared completely. I didn't upload a .love vecause my game is nearing completion, and I don't want it sitting on a public forum particularly -- not till it's out for sale. However it seems like this isn't a known bug? I'll try reproducing it in a smaller example file.

Thanks,
Are you popping your state too early?
luminosity
Prole
Posts: 34
Joined: Fri Sep 24, 2010 5:46 am

Re: love.graphics.translate & printf

Post by luminosity »

Okay boiled down to code that is breaking:

Code: Select all

function love.draw()
	love.graphics.push()
	love.graphics.translate(100, 100)
	love.graphics.printf("Testing", 100, 100, 1000, "left")
	love.graphics.printf("Testing", 100, 120, 1000, "left")
end
which gives me the following screenshot
Attachments
printfbug.png
printfbug.png (37.28 KiB) Viewed 1272 times
User avatar
thelinx
The Strongest
Posts: 852
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: love.graphics.translate & printf

Post by thelinx »

Not sure if this is an error in just your demo code, but try to .pop() before the end of your draw.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: love.graphics.translate & printf

Post by Boolsheet »

thelinx is right, you have to keep the push and pops balanced. The example code fills the matrix stack and runs out of space.
This fails silently in LÖVE 0.7.2. The next version will throw a Lua error once the stack is full.
Shallow indentations.
luminosity
Prole
Posts: 34
Joined: Fri Sep 24, 2010 5:46 am

Re: love.graphics.translate & printf

Post by luminosity »

Thanks guys. I swear it used to be balanced in my own game, but I guess I missed something. Will go back and look now. :)

Should there be a note in the wiki about this? The page for love.graphics.push doesn't explicitly say that pop/pushes must be balanced.

Thanks again.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: love.graphics.translate & printf

Post by tentus »

luminosity wrote:Thanks guys. I swear it used to be balanced in my own game, but I guess I missed something. Will go back and look now. :)

Should there be a note in the wiki about this? The page for love.graphics.push doesn't explicitly say that pop/pushes must be balanced.

Thanks again.
I dunno, I went to the wiki to add your suggestion, but it already has this line:
love.graphics.push wrote:This function is always used to prepare for a corresponding pop operation later
I guess we could word that stronger, but it pretty much tells you that you need a call to pop later.
Kurosuke needs beta testers
Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests