Squished Pixels - Canvas Scaling

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
Vjalmr
Prole
Posts: 1
Joined: Tue Apr 14, 2015 12:53 am
Location: Norway

Squished Pixels - Canvas Scaling

Post by Vjalmr »

Hello!

I am attempting to draw to a canvas and scale it while keeping the aspect ratio (black bars).
My previous attempt at this have worked, but now I am facing a bit of a problem that I cannot seem to fix.

The pixels of my assets are sometimes "squished" when resizing the window.

Here is my scaling function (I am using fennel, but will supply a lua translation)

Code: Select all

;; fennel
(fn calc-scale [window canvas]
  (let [scale-x (/ window.width canvas.width)
        scale-y (/ window.height canvas.height]
    (if (>= scale-x scale-y)
        scale-y
        scale-x)))

Code: Select all

-- lua
function calc-scale (window canvas)
	local scaleX = window.width / canvas.width
	local scaleY = window.height / canvas.height
	if scaleX >= scaleY then
		return scaleY
	else
		return scaleX
	end
end
I set the render target to the canvas, do my drawing, reset the target and draw the canvas with an offset and the calculated scale - pretty straight forward.

In the attachments you can hopefully see that some of the rows and some of the columns are "squished". I have attempted to search for this but I haven't found any help on the matter. Any ideas?

Thank you in advance.
Attachments
Some rows and columns are "squished"
Some rows and columns are "squished"
2025-02-02-201755_399x291_scrot.png (3.99 KiB) Viewed 1234 times
- Vjalmr
User avatar
steVeRoll
Party member
Posts: 141
Joined: Sun Feb 14, 2016 1:13 pm

Re: Squished Pixels - Canvas Scaling

Post by steVeRoll »

This usually happens when you scale with non-integer numbers. You probably want to round the scaling with math.floor.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 5 guests