bad argument #1 to 'draw' (Drawable expected, got nil)
Posted: Tue Oct 06, 2020 1:23 pm
Newbie with Löve here, hi.
I'm trying to display an arrow sprite from a class with this code.
When I run this, it throws this error;
I tried to look for information about it in the forums but all I got was even more confused, so I come here to ask, please could you explain to me how what I'm trying to do is supposed to be done?
Nowadays I attach the .love file of all what I have of the project in case the error is in the main.lua
I'm trying to display an arrow sprite from a class with this code.
Code: Select all
Arrow = Class{}
function Arrow:init(x, y, r)
self.image = love.graphics.newImage('arrowpic.png')
self.width = self.image:getWidth()
self.height = self.image:getHeight()
self.x = x
self.y = y
self.ox = self.width / 2
self.oy = self.height / 2
self.rotation = math.deg(0)
end
function Arrow:update(dt)
if love.keyboard.wasPressed('space') then
self.rotation = math.deg(90)
end
if love.keyboard.wasPressed('up') then
if self.rotation == math.deg(0) then
self.y = self.y - 49
elseif self.rotation == math.deg(90) then
self.x = self.x + 49
elseif self.rotation == math.deg(180) then
self.y = self.y + 49
elseif self.rotation == math.deg(270) then
self.x = self.x - 49
end
end
end
function Arrow:render()
love.graphics.draw(self.image, self.x, self.y, self.rotation, 0, 0, self.ox, self.oy)
end
Code: Select all
Error
Arrow.lua:41: bad argument #1 to 'draw' (Drawable expected, got nil)
Traceback
[C]: in function 'draw'
Arrow.lua:41: in function 'render'
main.lua:140: in function 'draw'
[C]: in function 'xpcall'
Nowadays I attach the .love file of all what I have of the project in case the error is in the main.lua