push icon indicating copy to clipboard operation
push copied to clipboard

Canvas Transformations not Preserved when Drawn in Update()

Open nequals30 opened this issue 5 years ago • 0 comments

When the game dimensions are a different aspect ratio than the screen dimensions, all canvases are drawn shifted relative to what they should be. It was an issue that was bugging me for a while, and pgimeno on the love2d forums helped me resolve it.

This only happens when the canvases are drawn in love.update (it works fine if the canvases are drawn in love.load).

pgimeno helped me resolve the issue by adding love.graphics.origin() before i draw the canvas. This resolves the issue, but the behaviour is still not what I'dve expect, so it might be considered a bug.

Example:

This should a 1280x720 blue rectangle over a 1280x720 game (when the screen is 1500x720):

The conf.lua

function love.conf(t)
	t.window.width = 1500
	t.window.height = 720
end

The main.lua:

push = require("push")

local gameWidth, gameHeight = 1280,720

local windowWidth, windowHeight = love.window.getMode()
push:setupScreen(gameWidth,gameHeight,windowWidth,windowHeight,{fullscreen=false})

function love.update(dt)
	thisCanvas = love.graphics.newCanvas(1280,720)
	love.graphics.setCanvas(thisCanvas)
	love.graphics.clear()

	love.graphics.setColor(0,1,1,1)
	love.graphics.rectangle('fill',0,0,1280,720)
	love.graphics.setColor(1,1,1,1)

	love.graphics.setCanvas()
end

function love.draw()
	push:start()

	love.graphics.rectangle('line',1,1,1280,720)
	love.graphics.draw(thisCanvas,0,0)

	push:finish()
end

The canvas (blue) appears shifted right relative to where it should be by 110px (which is the same as how much the game is shifted relative to the screen, but this is an extra 110px on top of that).

nequals30 avatar Dec 27 '20 05:12 nequals30