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
Can't draw an image...
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Can't draw an image...
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".
Or maybe it's actually "panda.jpg".
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 2 guests