Camera jittering

General discussion about LÖVE, Lua, game development, puns, and unicorns.
gcmartijn
Party member
Posts: 136
Joined: Sat Dec 28, 2019 6:35 pm

Re: Camera jittering

Post 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)

RNavega
Party member
Posts: 251
Joined: Sun Aug 16, 2020 1:28 pm

Re: Camera jittering

Post by RNavega »

@ddabrahim can you test this?
preview.gif
preview.gif (33.9 KiB) Viewed 1071 times
The "sprite.png" image is this:
sprite.png
sprite.png (466 Bytes) Viewed 1071 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
RNavega
Party member
Posts: 251
Joined: Sun Aug 16, 2020 1:28 pm

Re: Camera jittering

Post 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
preview.png (15.63 KiB) Viewed 1061 times
Attachments
Parallax_Scrolling.love
(12.1 KiB) Downloaded 45 times
User avatar
ddabrahim
Party member
Posts: 183
Joined: Mon May 17, 2021 8:05 pm
Contact:

Re: Camera jittering

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 64 guests