Page 1 of 1

Images

Posted: Wed Aug 10, 2022 10:07 pm
by _Rocoo_
How do i put images in my thing (not game yet), i make sure the name is right and... i'm not very sure about the code, here is it

Code: Select all

function love.load()
  x = 0
  y = 0
  mv = 10
  slime = love.graphics.newImage("frame_up.png")
end

function love.draw()
    love.graphics.draw("slime", x, y)
end

function love.update()
  if x > 600 then
   x = x - mv
  end
  if y > 400 then
   y = y - mv
  end
  if x < 0 then
   x = x + mv
  end
  if y < 0 then
   y = y + mv
  end
  if love.keyboard.isDown("d") then
     x = x + mv
  end
  if love.keyboard.isDown("s") then
     y = y + mv
  end
  if love.keyboard.isDown("a") then
     x = x - mv
  end
  if love.keyboard.isDown("w") then
     y = y - mv
  end
 
end

it gives me this error
Error

main.lua:5: Could not open file frame_up.png. Does not exist.


Traceback

[love "callbacks.lua"]:228: in function 'handler'
[C]: in function 'newImage'
main.lua:5: in function 'load'
[love "callbacks.lua"]:136: in function <[love "callbacks.lua"]:135>
[C]: in function 'xpcall'
[C]: in function 'xpcall'

Re: Images

Posted: Wed Aug 10, 2022 10:56 pm
by BrotSagtMist
In love.draw you need to use love.graphics.draw.
newImage just creates a new object then throws it away.
edit: Actually what is newPaddedImage supposed to be? You want to create the image here...

Re: Images

Posted: Wed Aug 10, 2022 11:09 pm
by togFox
As Brot said: load the image in love.load then draw the image in love.draw.

Re: Images

Posted: Thu Aug 11, 2022 1:50 pm
by milon
_Rocoo_ wrote: Wed Aug 10, 2022 10:07 pm How do i put images in my thing (not game yet), i make sure the name is right and... i'm not very sure about the code, here is it
For ease of readability on the forums, you can use [ code ] tags like this:

Code: Select all

function love.load()
  frame = newPaddedImage("frame_up.png")
  x = 0
  y = 0
  mv = 10
end

function love.draw()
    love.graphics.newImage(frame, x, y)

end

function love.update()
  if x > 600 then
   x = x - mv
  end
  if y > 400 then
   y = y - mv
  end
  if x < 0 then
   x = x + mv
  end
  if y < 0 then
   y = y + mv
  end
  if love.keyboard.isDown("d") then
     x = x + mv
  end
  if love.keyboard.isDown("s") then
     y = y + mv
  end
  if love.keyboard.isDown("a") then
     x = x - mv
  end
  if love.keyboard.isDown("w") then
     y = y - mv
  end
 
end

Re: Images

Posted: Fri Aug 12, 2022 3:39 pm
by k1ngS4krifice
Use this for load the image:

Code: Select all

function love.load()
	image = love.graphics.newImage("name.png")
end
and this for draw it

Code: Select all

function love.draw()
	love.graphics.draw(image, x, y)
end