Images

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
_Rocoo_
Prole
Posts: 2
Joined: Wed Aug 10, 2022 10:02 pm

Images

Post 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'
Last edited by _Rocoo_ on Sun Aug 14, 2022 5:37 pm, edited 1 time in total.
User avatar
BrotSagtMist
Party member
Posts: 612
Joined: Fri Aug 06, 2021 10:30 pm

Re: Images

Post 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...
obey
User avatar
togFox
Party member
Posts: 774
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: Images

Post by togFox »

As Brot said: load the image in love.load then draw the image in love.draw.
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

Re: Images

Post 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
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
User avatar
k1ngS4krifice
Prole
Posts: 10
Joined: Fri Aug 12, 2022 3:27 pm
Location: Mexico

Re: Images

Post 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
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 35 guests