Page 2 of 2
Re: Camera jittering
Posted: Sun Jan 28, 2024 7:06 pm
by gcmartijn
I'm using a old macbook air 2014...
I can't give the whole code but i'm using quad for animations.
Something like this.
Code: Select all
init
love.graphics.newQuad(frame.quad.x, frame.quad.y, frame.quad.w, frame.quad.h, self.resource:getDimensions())
update
if update then
self.time = self.time + dt
if self.time >= (currentFrame.duration / 1000) then
self.framekey = (self.framekey % #self.frames) + 1
self.time = 0
end
end
draw
love.graphics.draw(frameset.resource, frameset:getQuad(), x, y, 0, frameset.scaleX, frameset.scaleY, ox, oy)
Re: Camera jittering
Posted: Mon Jan 29, 2024 3:21 am
by RNavega
@ddabrahim can you test this?
- preview.gif (33.9 KiB) Viewed 1939 times
The "sprite.png" image is this:
- sprite.png (466 Bytes) Viewed 1939 times
The main.lua code is this:
Code: Select all
local sprite
local spriteX = 170
local pixelCanvas
function love.load()
love.window.setMode(640, 400) -- Twice the pixel art canvas size.
love.graphics.setDefaultFilter('nearest', 'nearest')
sprite = love.graphics.newImage('sprite.png')
pixelCanvas = love.graphics.newCanvas(320, 200)
end
function love.update(dt)
spriteX = spriteX + 1.0 * dt
end
function love.keypressed(key)
if key == 'escape' then
love.event.quit()
end
end
function love.draw()
love.graphics.setCanvas(pixelCanvas)
love.graphics.clear()
love.graphics.draw(sprite, 320 - 64 - 2, 2)
love.graphics.translate(0.2, -14.333)
love.graphics.rotate(0.1)
love.graphics.draw(sprite, spriteX, 2)
love.graphics.origin()
love.graphics.setCanvas()
love.graphics.print('Press Esc to quit.', 10, 10)
love.graphics.draw(pixelCanvas, 0, 0, 0, 2.0, 2.0)
end
Re: Camera jittering
Posted: Mon Jan 29, 2024 5:44 am
by RNavega
Actually, f*** it, let's go all out.
There's no better way to test nearest-neighbor filtering than some parallax scrolling with a very subtle decay.
- preview.png (15.63 KiB) Viewed 1929 times
Re: Camera jittering
Posted: Mon Jan 29, 2024 9:22 pm
by ddabrahim
@gcmartijn I never used quads before. Maybe I should look in to them. At the moment for animation I simply store all images of all frames in a list and then to play animation I simply iterate through the list every frame as I draw the object. Not sure if it's a good way to do it, but works for the most part.
@RNavega Thanks a lot for the examples. I think it is certainly my hardware because I can see jittering in both examples you shared if I move slowly. But I have noticed if I rotate the object even just as small as 1 degree as you did in your example, the jitter is much more tolerable.
The parallax example is awesome and there is no jitter as I move the mouse around but if I slow things down then I can see a bit of jittering but it is not too bad compared to what I had. Considering it is pixel art I think it is perfectly fine.
Thanks a lot really appreciate all the help.