Image load? [SOLVED]

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.
Todespreis
Prole
Posts: 40
Joined: Sat Apr 01, 2023 9:30 pm

Image load? [SOLVED]

Post by Todespreis »

Hey there! I have a problem with an image file. My code is still at the beginning:
function love.load()

player = love.graphics.newImage"Player.png"

player = {}
player.x = 70
player.y = 70

end
function love.draw()

love.graphics.draw(player)

end

the compiler says: "could not find love.image!" Why that? Is the png file format not supported? Or do i do something wrong?
Last edited by Todespreis on Mon Jun 19, 2023 10:11 am, edited 1 time in total.
User avatar
dusoft
Party member
Posts: 655
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Image load?

Post by dusoft »

you are overwriting

Code: Select all

player
variable by assigning empty table to it.

PS: Also use the full editor to format your code rather than the mess you provided.
User avatar
darkfrei
Party member
Posts: 1204
Joined: Sat Feb 08, 2020 11:09 pm

Re: Image load?

Post by darkfrei »

Todespreis wrote: Thu Jun 15, 2023 8:56 pm Hey there! I have a problem with an image file. My code is still at the beginning:
function love.load()

player = love.graphics.newImage"Player.png"

player = {}
player.x = 70
player.y = 70

end
function love.draw()

love.graphics.draw(player)

end

the compiler says: "could not find love.image!" Why that? Is the png file format not supported? Or do i do something wrong?

Code: Select all

function love.load()
	player = {}
	player.x = 70
	player.y = 70
	player.image = love.graphics.newImage ("player.png") -- be sure that the file is near the main.lua
end
function love.draw()
    love.graphics.draw(player.image, player.x, player.y)
end
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Todespreis
Prole
Posts: 40
Joined: Sat Apr 01, 2023 9:30 pm

Re: Image load?

Post by Todespreis »

Hey there! Thank you for the fast reply, so i tried it out and this is, what worked at the end:

Code: Select all

 local player




function love.load()
    
   
    player = {}
    player.x = 70
    player.y = 70
    
    player = love.graphics.newImage( "Player.png" )


end


Down={}
function love.joystickpressed( joystick, button )
  Down[button]=true
end
function love.joystickreleased( joystick, button )
  Down[button]=nil
end

love.update=function (dt)
    
    if Down[06] then 
        player.x = player.x + 1
    end

    if Down[04] then 
        player.y = player.y + 1
    end

    if Down[02] then 
        player.x = player.x - 1
    end

    if Down[00] then 
        player.y = player.y - 1
    end

end



function love.draw()
    
    love.graphics.draw( player, player.x, player.y )

end
 
I tried to implement the image in different ways - with brackets and without, within the same directory as main or in a Folder "Assets/Graphics". Nothing worked, but then i saw, that the image implementation was "false" in the config file O.O" I'm sorry L(^ - ^)I
Todespreis
Prole
Posts: 40
Joined: Sat Apr 01, 2023 9:30 pm

Re: Image load?

Post by Todespreis »

I still have 2 questions to it - is it necessary to implement the vector(?)

Code: Select all

 player = { } 
before

Code: Select all

 player = love.graphics.newImage 
?
Does it have any differences?
And @dusoft can you recommend any? I have the problem, that i'm trying to write the code for an old device named GP2X. @SCIENCE, a user here on the forum ported it backdays on Caanoo and another player ported it on my device. The version of the Love2d is 0.7, i think. So i can't use such things like visual studio code, where the Love2d core is just not compatible due to its version
User avatar
darkfrei
Party member
Posts: 1204
Joined: Sat Feb 08, 2020 11:09 pm

Re: Image load?

Post by darkfrei »

Todespreis wrote: Fri Jun 16, 2023 12:18 pm
I tried to implement the image in different ways - with brackets and without, within the same directory as main or in a Folder "Assets/Graphics". Nothing worked, but then i saw, that the image implementation was "false" in the config file O.O" I'm sorry L(^ - ^)I
Wrong:

Code: Select all

player = love.graphics.newImage ("player.png")
Right:

Code: Select all

player.image = love.graphics.newImage ("player.png")
OR just

Code: Select all

player = {
	x = 70,
	y = 70,
	image = love.graphics.newImage ("player.png"),
}
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Todespreis
Prole
Posts: 40
Joined: Sat Apr 01, 2023 9:30 pm

Re: Image load?

Post by Todespreis »

But it worked. And like i said, my version of Love2d is 12 years old
Todespreis
Prole
Posts: 40
Joined: Sat Apr 01, 2023 9:30 pm

Re: Image load?

Post by Todespreis »

And thanks for replying :-)
User avatar
darkfrei
Party member
Posts: 1204
Joined: Sat Feb 08, 2020 11:09 pm

Re: Image load?

Post by darkfrei »

Todespreis wrote: Fri Jun 16, 2023 1:18 pm But it worked. And like i said, my version of Love2d is 12 years old
Yes, it worked, but on this assignment you loose your x and y variables.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Todespreis
Prole
Posts: 40
Joined: Sat Apr 01, 2023 9:30 pm

Re: Image load?

Post by Todespreis »

If i change player to player.image, the compiler says: "Incorrect parameter type: expected userdata." in love.graphics.draw.
Sorry, it's just as hard as learning a new language - i have to look up every single word, function and character
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 7 guests