Can't move my Sprite
Posted: Wed Dec 23, 2020 4:33 am
I've got my image uploaded into the game, and I've coded for it to move a specific direction when I press the 'w', 'a', 's' and 'd' buttons. But when I load the game, the image is not moving.
Here's my code:
I'm sort of new to coding, so I don't know what I'm doing wrong.
Here's my code:
Code: Select all
Player = Class{}
local MOVE_SPEED = 140
function Player:init(map)
self.width = 16
self.height = 20
self.x = map.tileWidth * 10
self.y = map.tileHeight * (map.mapHeight - 2) - self.height
self.texture = love.graphics.newImage('images/Harry final.png')
self.frames = generateQuads(self.texture, 32, 32)
end
function Player:update(dt)
if love.keyboard.isDown('a') then
self.x = self.x - MOVE_SPEED * dt
elseif love.keyboard.isDown('d' ) then
self.x = self.x + MOVE_SPEED * dt
elseif love.keyboard.isDown('w') then
self.y = self.y - MOVE_SPEED * dt
elseif love.keyboard.isDown('s') then
self.y = self.y + MOVE_SPEED * dt
end
end
function Player:render()
love.graphics.draw(self.texture, self.frames[2], self.x, self.y)
end