This is what i'm doing in example 2, and the movement is not smooth. Is there something wrong with how i coded example 2?
Problems with slow movement speeds
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 13
- Joined: Mon Mar 15, 2021 9:00 pm
Re: Problems with slow movement speeds
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?
Also speed_x can be not same as speed_y.
-
- Prole
- Posts: 13
- Joined: Mon Mar 15, 2021 9:00 pm
Re: Problems with slow movement speeds
y 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?
Re: Problems with slow movement speeds
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?
viewtopic.php?f=4&t=90455#p239262
-
- Prole
- Posts: 13
- Joined: Mon Mar 15, 2021 9:00 pm
Re: Problems with slow movement speeds
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
It seems that your suggested solution is to run a conditional if statement on every frame for every moving object to determine if the buffer is large enough to be rounded safely. that's what the buffer is, right? is this the best solution? it seems janky.
is the buffer system your suggested solution? is there anything else i can do with the mathematics in example 2 to fix this problem instead of using the buffer?
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?
Re: Problems with slow movement speeds
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?
Also please test the code with positive y, maybe your error is here.
-
- Prole
- Posts: 13
- Joined: Mon Mar 15, 2021 9:00 pm
Re: Problems with slow movement speeds
subtracting y makes the rectangle move upwards instead of downwards.
changing this does not help, as you can see be running the code below, which contains your suggested changes. this is not helpful
do you have any other suggestions, hopefully suggestions that you test by running the code before making the suggestion?
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
Re: Problems with slow movement speeds
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?
Which "push" lib are you using? This one? https://github.com/Ulydev/push
-
- Prole
- Posts: 13
- Joined: Mon Mar 15, 2021 9:00 pm
Re: Problems with slow movement speeds
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.
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.
Re: Problems with slow movement speeds
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.
Just zip your files (not folder!) And rename it into the *.love
Last edited by darkfrei on Tue Mar 16, 2021 8:06 pm, edited 1 time in total.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 8 guests