Re: Problems with slow movement speeds
Posted: Tue Mar 16, 2021 3:30 pm
I see the problem that you make x=x+dt*speed, but the minus by the y.placeholder wrote: ↑Tue Mar 16, 2021 3:30 pmThis is what i'm doing in example 2, and the movement is not smooth. Is there something wrong with how i coded example 2?
y is minus so that the rectangle moves upwards instead of down. this is not a problem.
I've updated this comment:placeholder wrote: ↑Tue Mar 16, 2021 3:39 pmy is minus so that the rectangle moves upwards instead of down. this is not a problem.
speed_x and speed_y do not exist in the example so i'm not sure what you mean, and an object can certainly move in more than one direction with a single speed variable.
how -SPECIFICALLY - do i adjust example 2 to make the movement smooth?
I'm not sure what specific update you made to the comment, or what specifically you intended to clarify.darkfrei wrote: ↑Tue Mar 16, 2021 3:40 pm
I've updated this comment:
viewtopic.php?f=4&t=90455#p239262
rect.draw_y = math.floor(rect.y - 0.5) -- not sure, but you use negative y;placeholder wrote: ↑Tue Mar 16, 2021 3:52 pm
also, why does example 2 not work? other posters also suggested the solution that i tried to implement in example 2, but it's causing stuttery movement. did i code example 2 wrong? am i misunderstanding? why is example 2 not working?
subtracting y makes the rectangle move upwards instead of downwards.
Code: Select all
push = require "push"
screenWidth = 160
screenHeight = 120
push:setupScreen(screenWidth, screenHeight, screenWidth * 4, screenHeight * 4)
io.stdout:setvbuf("no")
-- please set EXAMPLE to 1 or 2
-- 1 generates smooth diagonal movement, but breaks if rect.speed is set to 25-ish or below
-- 2 works at slow speed, but generates stuttery movement at all speeds FOR SOME REASON??
EXAMPLE = 2
function love.load()
rect = {
x = 5,
y = 5,
width = 10,
height = 10,
draw_x = 5,
draw_y = 5,
speed = 40
}
end
function love.update(dt)
if EXAMPLE == 1 then
--
rect.x = rect.x + rect.speed * dt
rect.y = rect.y + rect.speed * dt
--
rect.x = math.floor(rect.x + 0.5)
rect.y = math.floor(rect.y + 0.5)
--
rect.draw_x = rect.x
rect.draw_y = rect.y
--
elseif EXAMPLE == 2 then
--
rect.x = rect.x + rect.speed * dt
rect.y = rect.y + rect.speed * dt
--
rect.draw_x = math.floor(rect.x + 0.5)
rect.draw_y = math.floor(rect.y + 0.5)
--
else
love.event.quit()
end
print(delta)
end
function love.draw()
push:start()
love.graphics.rectangle("fill", rect.draw_x, rect.draw_y, rect.width, rect.height)
push:finish()
end
It must be much easier if you provide the .love fileplaceholder wrote: ↑Tue Mar 16, 2021 4:59 pm do you have any other suggestions, hopefully suggestions that you test by running the code before making the suggestion?
I've never heard about this lib, just googled it as "Love2d push", but wasn't sure if it's the right one.placeholder wrote: ↑Tue Mar 16, 2021 7:25 pm yes, i am using that library. i have read that it is very commonly used, and i assumed that everyone here would have it already.
i'm sorry for not posting in the correct format, but i am just learning. i don't know how to export a file yet.
but the code is very short, and it takes only a second to copy paste into a new project folder with the push.lua file in it.