Love.graphics.captureScreenshot producing no file!

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
crocs
Prole
Posts: 4
Joined: Mon Oct 03, 2022 2:57 pm

Love.graphics.captureScreenshot producing no file!

Post by crocs »

Hello! I've checked the wiki and I don't think anybody else had this problem, probably because I am doing something really stupid.
This is some WIP art/screensaver that connects dots to lines that just runs on a main.lua file that I am going to send.

If you press Q, it should take a screenshot, and LOVE will freeze for a little bit when you click it, so it has to be doing something! But when I check my folder for a the PNG file it is just not there!

Here's all of the code!

Code: Select all

local POINTS = 500
local RESX, RESY = love.window.getDesktopDimensions()
local SINPOWERMULT = 20
local LINEWIDTH = 1
local CONNECTORS = 3

local allPoints = {}
local rt = 0
local qDown = false

function mag(x,y)
    return (x ^ 2 + y ^ 2) ^ 0.5
end

function love.load()
    for i = 1,POINTS do
        table.insert(allPoints, 
        {
            x = love.math.random() * RESX,
            y = love.math.random() * RESY,
            pwr = (love.math.random() + 0.5) * SINPOWERMULT,
            xoffset = love.math.random() * 180,
            yoffset = love.math.random() * 180,
            sinmult = love.math.random() + 0.5,
            connector = 1,
            DX = 0,
            DY = 0
        })
    end

    love.graphics.setLineWidth(LINEWIDTH)
    love.window.setFullscreen(true)
end

function love.draw()
    for _,point in ipairs(allPoints) do
        love.graphics.circle("fill",point.DX, point.DY ,LINEWIDTH / 2)

        local connectedPoint = allPoints[point.connector]
        love.graphics.line(point.DX, point.DY, connectedPoint.DX, connectedPoint.DY)
    end
end

function love.update(dt)
    rt = rt + dt

    for i,point in ipairs(allPoints) do
        local NFX, NFY = point.x + point.pwr * math.sin(rt * point.sinmult + point.xoffset), point.y + point.pwr * math.sin(rt * point.sinmult + point.yoffset)
        local inverseForceX, inverseForceY = 0,0

        local closestIndex, closestPoint = 0,9999999

        for j, forcePoint in ipairs(allPoints) do
            local newForceX, newForceY = NFX -  forcePoint.DX, NFY - forcePoint.DY
            local magnitude = mag(newForceX, newForceY)

            newForceX, newForceY = newForceX / magnitude, newForceY / magnitude
            inverseForceX, inverseForceY = inverseForceX + newForceX, inverseForceY + newForceY

            if magnitude < closestPoint and i ~= j then
                closestIndex, closestPoint = j, magnitude
            end
        end

        point.connector = closestIndex
        point.DX, point.DY = NFX + inverseForceX, NFY + inverseForceY

    end

    if love.keyboard.isDown("q") then
        if qDown == false then
            qDown = true
            love.graphics.captureScreenshot("capture.png")                                       --SCREENSHOTTING HAPPENS HERE HELLO !!
        end
    else[/b]
        qDown = false
    end
end
Any help would be really appreciated, and it's probably something really obvious :o: , thanks.
User avatar
BrotSagtMist
Party member
Posts: 657
Joined: Fri Aug 06, 2021 10:30 pm

Re: Love.graphics.captureScreenshot producing no file!

Post by BrotSagtMist »

Works for me, youre looking in the wrong folder i guess, its saving to the users data, NOT the working dir.
Nice looking btw, but for a screensaver you need to trim a bit of cpu usage.
Get the button over a callback for example.
obey
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

Re: Love.graphics.captureScreenshot producing no file!

Post by Bigfoot71 »

Because the image is saved in the Löve2D "save folder", i.e. for the example of the wiki:

Code: Select all

function love.load()
    love.filesystem.setIdentity("screenshot_example")
end

function love.keypressed(key)
    if key == "c" then
        love.graphics.captureScreenshot(os.time() .. ".png")
    end
end

function love.draw()
    love.graphics.circle("fill", 400, 300, 200)
end
For me who is on Linux it will be in this directory: /home/<user_name>/.local/share/love/screenshot_example/
On Windows it will be: C:\Users\user\AppData\Roaming\LOVE or %appdata%\LOVE\

See here: https://love2d.org/wiki/love.filesystem
You can also see this: https://love2d.org/wiki/love.filesystem.setIdentity

You can also configure all this in the conf.lua.
My avatar code for the curious :D V1, V2, V3.
User avatar
knorke
Party member
Posts: 274
Joined: Wed Jul 14, 2010 7:06 pm
Contact:

Re: Love.graphics.captureScreenshot producing no file!

Post by knorke »

I use this to open/find the save folder:

Code: Select all

love.system.openURL("file://"..love.filesystem.getSaveDirectory())
crocs
Prole
Posts: 4
Joined: Mon Oct 03, 2022 2:57 pm

Re: Love.graphics.captureScreenshot producing no file!

Post by crocs »

Bigfoot71 wrote: Wed Mar 01, 2023 4:21 pm Because the image is saved in the Löve2D "save folder", i.e. for the example of the wiki:

Code: Select all

function love.load()
    love.filesystem.setIdentity("screenshot_example")
end

function love.keypressed(key)
    if key == "c" then
        love.graphics.captureScreenshot(os.time() .. ".png")
    end
end

function love.draw()
    love.graphics.circle("fill", 400, 300, 200)
end
For me who is on Linux it will be in this directory: /home/<user_name>/.local/share/love/screenshot_example/
On Windows it will be: C:\Users\user\AppData\Roaming\LOVE or %appdata%\LOVE\

See here: https://love2d.org/wiki/love.filesystem
You can also see this: https://love2d.org/wiki/love.filesystem.setIdentity

You can also configure all this in the conf.lua.
Thank you, I checked my Appdata and found it there! The problem was just that I was looking in the wrong directory.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 4 guests