Can't move my Sprite

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
Shadow3489
Prole
Posts: 8
Joined: Mon Dec 21, 2020 5:36 am

Can't move my Sprite

Post by Shadow3489 »

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:

Re: Can't move my Sprite

Post by sphyrth »

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

Re: Can't move my Sprite

Post by Shadow3489 »

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!
Post Reply

Who is online

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