Text not centralizing

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Kibita
Prole
Posts: 31
Joined: Tue Dec 29, 2015 7:46 pm

Text not centralizing

Post by Kibita »

Hey there!

I'm facing a problem where I can't centralize right my title:
Image

How can I make the text centralize correctly? I did this:

Code: Select all

-- Title
self.title = {}
self.title.text = "Sample Text"
self.title.width = fonts.menu:getWidth(self.title.text)
self.title.x = const.gameWidth / 2 - self.title.width / 2
self.title.y = 15

[....]

-- Draw title
love.graphics.setFont(fonts.title)
love.graphics.print(self.title.text, self.title.x, self.title.y)
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Text not centralizing

Post by s-ol »

You are using fonts.title to draw it but fonts.menu to calculate the width.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
Kibita
Prole
Posts: 31
Joined: Tue Dec 29, 2015 7:46 pm

Re: Text not centralizing

Post by Kibita »

My god! Didn't noticed that. Anyway, thank you very much! I understood the difference now.
User avatar
NickRock
Citizen
Posts: 76
Joined: Thu Dec 25, 2014 9:33 pm
Location: Earth
Contact:

Re: Text not centralizing

Post by NickRock »

These little mistakes are always so annoying right? :P
Weeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeooow!!
Post Reply

Who is online

Users browsing this forum: No registered users and 232 guests