Image twitches when moving how to fix it ?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
n0bleman
Prole
Posts: 10
Joined: Mon Sep 30, 2019 9:40 pm

Image twitches when moving how to fix it ?

Post by n0bleman »

local x = 300
local y = 300
function love.load()
head = love.graphics.newImage("head.png")
head:setFilter('nearest')
end
function love.draw()
love.graphics.draw(head, x, y,0,5,5)
end
function love.update(deltatime)
x = x + (30 * deltatime)
end


But when i use this camera follow library for follow image he not twitches ? why! and how fix it without camera moving follow him?
camera = {}
camera.x = 0
camera.y = 0
camera.scaleX = 1
camera.scaleY = 1
camera.rotation = 0

function camera:set()
love.graphics.push()
love.graphics.rotate(-self.rotation)
love.graphics.scale(1 / self.scaleX, 1 / self.scaleY)
love.graphics.translate(-self.x, -self.y)
end

function camera:unset()
love.graphics.pop()
end

function camera:move(dx, dy)
self.x = self.x + (dx or 0)
self.y = self.y + (dy or 0)
end

function camera:rotate(dr)
self.rotation = self.rotation + dr
end

function camera:scale(sx, sy)
sx = sx or 1
self.scaleX = self.scaleX * sx
self.scaleY = self.scaleY * (sy or sx)
end

function camera:setPosition(x, y)
self.x = x or self.x
self.y = y or self.y
end

function camera:setScale(sx, sy)
self.scaleX = sx or self.scaleX
self.scaleY = sy or self.scaleY
end
User avatar
EngineerSmith
Prole
Posts: 38
Joined: Thu Dec 02, 2021 11:38 am
Contact:

Re: Image twitches when moving how to fix it ?

Post by EngineerSmith »

The issue is with drawing it at a decimal place most likely. Should only draw at perfect integers using something along the lines of the following:

Code: Select all

math.floor(x) -- or
math.ceil(x)
-- example
love.graphics.draw(head, math.floor(x), math.floor(y))
This will draw it correctly than it being on the edge of a pixel
n0bleman
Prole
Posts: 10
Joined: Mon Sep 30, 2019 9:40 pm

Re: Image twitches when moving how to fix it ?

Post by n0bleman »

EngineerSmith wrote: Thu Jan 13, 2022 2:18 pm The issue is with drawing it at a decimal place most likely. Should only draw at perfect integers using something along the lines of the following:

Code: Select all

math.floor(x) -- or
math.ceil(x)
-- example
love.graphics.draw(head, math.floor(x), math.floor(y))
This will draw it correctly than it being on the edge of a pixel
dont work still same! may be double buffer need function or somthing else but strange when i move image with camera library all OK! its drawing problem i think

function love.draw()

love.graphics.draw(head, math.floor(x), math.floor(y),0,5,5)
end
function love.update(deltatime)
x = x + (20 * deltatime)
end
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 12 guests