Can't draw an image...

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
Tal20081
Prole
Posts: 1
Joined: Sat Nov 14, 2020 3:09 pm

Can't draw an image...

Post 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
sphyrth
Party member
Posts: 260
Joined: Mon Jul 07, 2014 11:04 am
Contact:

Re: Can't draw an image...

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

Who is online

Users browsing this forum: Bing [Bot] and 4 guests