Page 1 of 2
Image load? [SOLVED]
Posted: Thu Jun 15, 2023 8:56 pm
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?
Re: Image load?
Posted: Thu Jun 15, 2023 9:08 pm
by dusoft
you are overwriting
variable by assigning empty table to it.
PS: Also use the full editor to format your code rather than the mess you provided.
Re: Image load?
Posted: Fri Jun 16, 2023 6:38 am
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
Re: Image load?
Posted: Fri Jun 16, 2023 12:18 pm
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
Re: Image load?
Posted: Fri Jun 16, 2023 12:37 pm
by Todespreis
I still have 2 questions to it - is it necessary to implement the vector(?)
before
?
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
Re: Image load?
Posted: Fri Jun 16, 2023 12:43 pm
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"),
}
Re: Image load?
Posted: Fri Jun 16, 2023 1:18 pm
by Todespreis
But it worked. And like i said, my version of Love2d is 12 years old
Re: Image load?
Posted: Fri Jun 16, 2023 1:19 pm
by Todespreis
And thanks for replying :-)
Re: Image load?
Posted: Fri Jun 16, 2023 1:27 pm
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.
Re: Image load?
Posted: Fri Jun 16, 2023 1:45 pm
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