thank you i will try this after workdarkfrei wrote: ↑Tue Mar 16, 2021 7:45 pmI've never heard about this lib, just googled it as "Lua2d 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
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
Re: Problems with slow movement speeds
You need to stop using push for that. (Edit: not quite, see below!)placeholder wrote: ↑Tue Mar 16, 2021 6:01 am how can i make my rectangle move smoothly like example 1 without breaking at low speed?
The stuttering is due to the poor resolution, 160x120 in a window of 640x480. Therefore the rectangle moves in increments of 4 pixels, which is why it looks like stuttering. The faster movement means that the object changes coordinates every frame, while the slower movement means that it stays in the same position for some frames until it can advance 4 screen pixels (one low-res pixel) at a time. That's the reason of the stuttering.
If you want the movement to look smooth, you need "sub-pixel" movement for the low-resolution pixels, i.e. normal-pixel movement, or just assume that with a resolution of 160x120, you will have that stuttering.
Last edited by pgimeno on Tue Mar 16, 2021 11:45 pm, edited 1 time in total.
-
- Prole
- Posts: 13
- Joined: Mon Mar 15, 2021 9:00 pm
Re: Problems with slow movement speeds
what i think i should do, based on your suggestion, is run the game at a much higher resolution, and then draw everything scaled down to the window size.
that's what i did in the code below, and it seems to solve the problem!
but this seems to solve the problem while still using push, as in the code below. if i can solve this problem and still use the push library, is there any other reason to stop using the library?
thanks!!!!
Code: Select all
scale = 10
push = require "push"
screenWidth = 160 * scale
screenHeight = 120 * scale
push:setupScreen(screenWidth, screenHeight, 640, 480)
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?? (AT LOW RESOLUTIONS)
EXAMPLE = 2
function love.load()
rect = {
x = 5,
y = 5,
width = 20 * scale,
height = 20 * scale,
draw_x = 5,
draw_y = 5,
speed = 40 * scale
}
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
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
No, no other reason. You did the right thing. I didn't think of the possibility of using push in "reverse"; it's usually used for retro-style low-res graphics.placeholder wrote: ↑Tue Mar 16, 2021 9:25 pm but this seems to solve the problem while still using push, as in the code below. if i can solve this problem and still use the push library, is there any other reason to stop using the library?
-
- Prole
- Posts: 13
- Joined: Mon Mar 15, 2021 9:00 pm
Re: Problems with slow movement speeds
Thank you all so much for helping me, this has been really instructive, and i've made tons of progress and solved lots of problems in the last couple days
Note to self - stop banging your head against things, and ask for help
Note to self - stop banging your head against things, and ask for help
Who is online
Users browsing this forum: Amazon [Bot], Google [Bot], steVeRoll and 2 guests