Page 1 of 1

Can't draw an image...

Posted: Sat Nov 14, 2020 3:15 pm
by Tal20081
I am learning love2d and I am in Chapter 14.

My code doesnt work for some reason, I tried copying the code but it also didn't work.
heres the error: Error

player.lua:21: bad argument #1 to 'draw' (Drawable expected, got nil)


Traceback

[C]: in function 'draw'
player.lua:21: in function 'draw'
main.lua:15: in function 'draw'
[C]: in function 'xpcall'


code:
Player = Object:extend()

function Player:new()
self.image = love.graphics.newImage("panda.png")
self.x = 300
self.y = 20
self.speed = 500
self.width = self.image:getWidth()
end

function Player:update()
if love.keyboard.isDown("left") then
self.x = self.x - self.speed * dt
elseif love.keyboard.isDown("right") then
self.x = self.x + self.speed * dt
end
end


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

Re: Can't draw an image...

Posted: Sun Nov 15, 2020 12:28 am
by sphyrth
Is "panda.png" inside the same folder as "main.lua"? Or is it inside a subfolder ("assets" for example)?

Or maybe it's actually "panda.jpg".