I have some sprites in my project moving around at various speeds and it's all doing well until the sprites/objects/whatever slow down, at which time they start hitching and stop moving. I'm using low resolution and some little pixel art sprites that I made to keep it simple because I have no idea what i'm doing yet
I made an example of what i'm seeing, and it's presented below. I'm using the push library.
This code breaks when the rect.speed variable is low. When rect.speed is 50-ish or above, the rectangle moves smoothly across the screen. When rect.speed = 10, the rectangle does not move. When rect.speed = 30, the rectangle moves in a lurching fashion that I would like to avoid.
I've tried removing the line that rounds the rect.x variable, but the result is again lurching movement that I would like to avoid. I'm not even sure what problem I'm trying to solve, or why this is breaking at low speed. I'm grateful for any suggestions, thanks!
Code: Select all
push = require "push"
screenWidth = 320
screenHeight = 240
push:setupScreen(screenWidth, screenHeight, screenWidth * 2, screenHeight * 2)
function love.load()
rect = {}
rect.x = 20
rect.y = 20
rect.width = 100
rect.height = 100
rect.speed = 10
end
function love.update(dt)
rect.x = rect.x + rect.speed * dt
rect.x = math.floor(rect.x + 0.5)
end
function love.draw()
push:start()
love.graphics.rectangle("line", rect.x, rect.y, rect.width, rect.height)
push:finish()
end