Can't draw an image...
Posted: Sat Nov 14, 2020 3:15 pm
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
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