Dynamic 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
Spunky
Prole
Posts: 3
Joined: Mon Mar 06, 2017 6:35 am

Dynamic Scaling?

Post by Spunky »

Hi all. I'm trying to scale a title screen (text element within Gspot) dynamically to any resolution. Basically I want to start drawing the text 1/4 from the left side of the window and stop drawing 1/4 distance from the right side of the window, and have it perfectly centered and scaled no matter the (widescreen) resolution selected. So far this has just been driving me crazy. No amount of Googling or searching these forums (which are HUGE) have yielded an answer. :(
User avatar
Ulydev
Party member
Posts: 445
Joined: Mon Nov 10, 2014 10:46 pm
Location: Paris
Contact:

Re: Dynamic Scaling?

Post by Ulydev »

Code: Select all

local w,h = love.graphics.getDimensions()
love.graphics.printf(text, w/4, h/2, w/2, "center")
For easy scaling I'd recommend you try push
Spunky
Prole
Posts: 3
Joined: Mon Mar 06, 2017 6:35 am

Re: Dynamic Scaling?

Post by Spunky »

Hmm how does that translate to Gspot button elements? Here's the code I have now:

Code: Select all

if love._version_major == 0 and love._version_minor < 9 then
	error("This library needs love2d 0.9.0 or above")
end

gui = require "gspot"

local tw, th = love.graphics.getDimensions()

font =
{
	name = "font/mainmenu_title.ttf",
	size = (tw - th) / 2 -- need to figure out how to scale font size appropriately
}

function love.load()
	local button = gui:button("Test", {x = (tw / 4), y = gui.style.unit, w = font.size, h = gui.style.unit}, nil, true)
	button:setfont(font.name, font.size)
	button.click = function(this, x, y)
		gui:feedback("Button works!")
	end
end

function love.update(dt)
	gui:update(dt)
end

function love.draw()
	gui:draw()
end

function love.mousepressed(x, y, button)
	gui:mousepress(x, y, button)
end

function love.mousereleased(x, y, button)
	gui:mouserelease(x, y, button)
end

function love.wheelmoved(x, y)
	gui:mousewheel(x, y)
end
As you can see there's no easy parameter for centering, so I have to do it manually.

Edit: It looks like push is exactly what I needed! Thank you so much!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests