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 .
Shadow3489
Prole
Posts: 8 Joined: Mon Dec 21, 2020 5:36 am
Post
by Shadow3489 » 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:
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
I'm sort of new to coding, so I don't know what I'm doing wrong.
sphyrth
Party member
Posts: 260 Joined: Mon Jul 07, 2014 11:04 am
Contact:
Post
by sphyrth » Wed Dec 23, 2020 4:39 am
I'm only assuming that you didn't call Player:update(dt) inside love.update(dt)
Shadow3489
Prole
Posts: 8 Joined: Mon Dec 21, 2020 5:36 am
Post
by Shadow3489 » Wed Dec 23, 2020 5:11 am
sphyrth wrote: ↑ Wed Dec 23, 2020 4:39 am
I'm only assuming that you didn't call
Player:update(dt) inside
love.update(dt)
Oh! Yep! That was it! Thank you!
Users browsing this forum: Bing [Bot] , RetroKevin and 4 guests