Page 1 of 1

How to setup project to pixel graphic?

Posted: Tue Oct 10, 2023 12:44 pm
by worona
Hey!

How can I configure the project correctly to correctly display small (16x16) sprites and fonts?

p.s. is there any project architecture recommended, such as ECS?

Re: How to setup project to pixel graphic?

Posted: Tue Oct 10, 2023 12:57 pm
by darkfrei
worona wrote: Tue Oct 10, 2023 12:44 pm Hey!

How can I configure the project correctly to correctly display small (16x16) sprites and fonts?

p.s. is there any project architecture recommended, such as ECS?
Hi and welcome to the forums! :awesome:

Code: Select all

love.graphics.setLineStyle ('rough')
love.graphics.setDefaultFilter ('nearest', 'nearest')

Code: Select all

font = love.graphics.newImageFont("graphics/font.png", " abcdefghijklmnopqrstuvwxyz" ..
	"ABCDEFGHIJKLMNOPQRSTUVWXYZ0" ..
	"123456789.,!?-+/():;%&`'*#=[]\"")
It will be nice to use a canvas and draw all graphics to it, then in the love.draw draw this canvas only.

Code: Select all

	canvas = love.graphics.newCanvas (width, height)
	local gWidth = love.graphics.getWidth ()
	local gHeight = love.graphics.getHeight ()
	scale = math.floor(math.min (gWidth/width, gHeight/height))
	print ('scale', scale)
	translateX = math.floor((gWidth - width*scale)/2)
	translateY = math.floor((gHeight - height*scale)/2)

Code: Select all

function draw ()
	love.graphics.setColor (1,1,1)
	love.graphics.draw (canvas, translateX, translateY, 0, scale, scale)
end

Re: How to setup project to pixel graphic?

Posted: Tue Oct 10, 2023 1:22 pm
by worona
darkfrei wrote: Tue Oct 10, 2023 12:57 pm
Hi and welcome to the forums! :awesome:
Thanks! :D