Camera panning not so smooth in map object

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
gcgsauce
Prole
Posts: 1
Joined: Mon Jun 10, 2019 9:58 am

Camera panning not so smooth in map object

Post by gcgsauce »

So the camera panning in my tile map level leaves a lot to be desired...not smooth. Can't figure out why, because fps is fine and I render less tiles on average than whats on the screen. Here's the class that most likely has the problem: https://pastebin.com/TtrWcwc8

one of the past versions of this class had much smoother panning, but other problems: https://pastebin.com/TtrWcwc8

to visit my repo on github so you can recreate it please visit: https://github.com/GCGsauce/RPG-Game-LUA

one can go to the second commit and run that to see the smooth panning, just make sure to copy the libraries folder to that project directory. thanks!
User avatar
unixfreak
Citizen
Posts: 82
Joined: Thu Oct 15, 2015 6:25 am
Location: Bristol, UK
Contact:

Re: Camera panning not so smooth in map object

Post by unixfreak »

Looks like you're missing deltatime when the camera position changes;

Something like this:

Map:update(dt)

Code: Select all

function Map:update(dt) --moves the map 1 pixel in any direction
    if input:down('PAN_RIGHT') then  
        self.camX = self.camX + 2 *dt
        print(self.camX)
    elseif input:down('PAN_LEFT') then
        self.camX = self.camX - 2 *dt
    end
 
    if input:down('PAN_UP') then
        self.camY = self.camY - 2 *dt
    elseif input:down('PAN_DOWN') then
        self.camY = self.camY + 2 *dt
    end
end
You'll probably want to increase "2" to a higher value also. The problem would be, that as it's not sync'd with delta time, every time the fps drops/increase the camera will end up moving variable to the actual framerate. So make sure you multiply by dt to factor that in.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 3 guests