[Solved] Taking a series of screenshots

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
User avatar
Tesselode
Party member
Posts: 555
Joined: Fri Jul 23, 2010 7:55 pm

[Solved] Taking a series of screenshots

Post by Tesselode »

love.load:

Code: Select all

screenshot_num=0
screenshot={}
screenshot_timer=0
love.update:

Code: Select all

screenshot_timer=screenshot_timer+love.timer.getDelta()
if screenshot_timer>(1/30) then
	screenshot_timer=0
	screenshot[screenshot_num]=love.graphics.newScreenshot()
	screenshot_num=screenshot_num+1
end
When closing the game:

Code: Select all

for a=1,screenshot_num-1 do
	love.filesystem.write(a..".bmp",love.image.newEncodedImageData(screenshot[a],"bmp"))
end
When I close the game, it saves the right number of bitmap files, but all of them are of the last screenshot taken. Anyone know why?
Last edited by Tesselode on Sat Oct 23, 2010 2:43 am, edited 2 times in total.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Taking a series of screenshots

Post by Robin »

Have you tried to encoding them earlier?
Tesselode wrote:

Code: Select all

screenshot_num=0
Don't you mean

Code: Select all

screenshot_num=1
?
In Lua, indexing starts at 1 (you do this correctly later)
Tesselode wrote:

Code: Select all

screenshot_timer=screenshot_timer+love.timer.getDelta()
One word: dt.

So, does:
Tesselode/Robin wrote:love.load:

Code: Select all

screenshot_num=1
screenshot={}
screenshot_timer=0
love.update:

Code: Select all

screenshot_timer=screenshot_timer+dt
if screenshot_timer>(1/30) then
	screenshot_timer=0
	screenshot[screenshot_num]=love.image.newEncodedImageData(love.graphics.newScreenshot(),"bmp")
	screenshot_num=screenshot_num+1
end
When closing the game:

Code: Select all

for a=1,screenshot_num-1 do
	love.filesystem.write(a..".bmp",screenshot[a])
end
work?
Help us help you: attach a .love.
User avatar
Tesselode
Party member
Posts: 555
Joined: Fri Jul 23, 2010 7:55 pm

Re: Taking a series of screenshots

Post by Tesselode »

Robin wrote:In Lua, indexing starts at 1
Can I start from 0? I'm used to it.

Also, love.timer.getDelta() seems to work pretty well. And I can't seem to get dt to work with functions called inside love.update.

And no, your code doesn't work, unfortunately.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Taking a series of screenshots

Post by Robin »

Tesselode wrote:
Robin wrote:In Lua, indexing starts at 1
Can I start from 0? I'm used to it.
You can, however I think it will be easier in the long run if you go along with the language's standard practice instead of trying to fight it.
Tesselode wrote:Also, love.timer.getDelta() seems to work pretty well. And I can't seem to get dt to work with functions called inside love.update.
You have to pass dt as an argument to the function being called to make it work. Also, getDelta() passes the Lua/C++ boundary, so it is slower, although perhaps only marginally so.
Tesselode wrote:And no, your code doesn't work, unfortunately.
Hm. I must confess I've never used the screenshot feature of LÖVE myself, so I don't know what would be the problem.
Help us help you: attach a .love.
User avatar
the_leg
Prole
Posts: 25
Joined: Sun Sep 05, 2010 3:43 am

Re: Taking a series of screenshots

Post by the_leg »

Try adding a dummy call to getPixel(0,0) right before you encode your image, like this:

Code: Select all

for a=1,screenshot_num-1 do
   screenshot[a]:getPixel(0,0)
   love.filesystem.write(a..".bmp",love.image.newEncodedImageData(screenshot[a],"bmp"))
end
The problem internally is love doesn't bind the image when you encode it. The result is love encodes the last bound image. The call to getPixel() causes the screenshot you're about to encode, to be bound.
User avatar
Tesselode
Party member
Posts: 555
Joined: Fri Jul 23, 2010 7:55 pm

Re: [Solved] Taking a series of screenshots

Post by Tesselode »

That worked. Thanks!
User avatar
the_leg
Prole
Posts: 25
Joined: Sun Sep 05, 2010 3:43 am

Re: [Solved] Taking a series of screenshots

Post by the_leg »

No problem. I reported this behavior in the issue tracker here.
Post Reply

Who is online

Users browsing this forum: Google [Bot], JarJarBinkks, Roland Chastain and 60 guests