How to setup project to pixel graphic?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
worona
Prole
Posts: 2
Joined: Tue Oct 10, 2023 11:46 am

How to setup project to pixel graphic?

Post 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?
User avatar
darkfrei
Party member
Posts: 1181
Joined: Sat Feb 08, 2020 11:09 pm

Re: How to setup project to pixel graphic?

Post 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
Attachments
license сс0
license сс0
font.png (1.06 KiB) Viewed 7044 times
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
worona
Prole
Posts: 2
Joined: Tue Oct 10, 2023 11:46 am

Re: How to setup project to pixel graphic?

Post by worona »

darkfrei wrote: Tue Oct 10, 2023 12:57 pm
Hi and welcome to the forums! :awesome:
Thanks! :D
Post Reply

Who is online

Users browsing this forum: No registered users and 56 guests