new and confused : player.img:getWidth()
Posted: Wed Mar 02, 2016 11:43 am
HI everyone,
i'm new to love 2d and tryting to follow the tutorial called : Your First Love2d Game in 200 Lines.
this is my code so far :
the love 2d stops when i press the right key and seems to dislike player.img:getWidth()
i get :
Error: main.lua:25: attempt to index field 'img' (a nil value)
stack traceback:
main.lua:25: in function 'update'
[string "boot.lua"]:461: in function <[string "boot.lua"]:433>
[C]: in function 'xpcall'
any help would be appreciated .
I was wondering it it had something to do with version 0.10 since the tutorial is in a previous build?
thanks
jp
i'm new to love 2d and tryting to follow the tutorial called : Your First Love2d Game in 200 Lines.
this is my code so far :
Code: Select all
-- http://osmstudios.com/tutorials/your-first-love2d-game-in-200-lines-part-1-of-3
debug = true
player = { x = 200, y = 710, speed = 150, img = nil }
function love.load(arg)
player.Img = love.graphics.newImage('assets/plane.png')
--we now have an asset ready to be used inside Love
end
-- Updating
function love.update(dt)
-- I always start with an easy way to exit the game
if love.keyboard.isDown('escape') then
love.event.push('quit')
end
if love.keyboard.isDown('left','a') then
if player.x > 0 then -- binds us to the map
player.x = player.x - (player.speed*dt)
end
elseif love.keyboard.isDown('right','d') then
if player.x < (love.graphics.getWidth() - player.img:getWidth() ) then
player.x = player.x + (player.speed*dt)
end
end
end
function love.draw(dt)
love.graphics.draw(player.Img, player.x , player.y)
end
i get :
Error: main.lua:25: attempt to index field 'img' (a nil value)
stack traceback:
main.lua:25: in function 'update'
[string "boot.lua"]:461: in function <[string "boot.lua"]:433>
[C]: in function 'xpcall'
any help would be appreciated .
I was wondering it it had something to do with version 0.10 since the tutorial is in a previous build?
thanks
jp