i am new to love2d, and I was just wondering if there is a way to find the center of a screen.
If there is any way to find out please tell me!
I have a question!
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: I have a question!
You can use:
http://www.love2d.org/wiki/love.graphics.getHeight
http://www.love2d.org/wiki/love.graphics.getWidth
to get the total height/width of the screen. If you divide them by 2, you get the middle of the screen.
http://www.love2d.org/wiki/love.graphics.getHeight
http://www.love2d.org/wiki/love.graphics.getWidth
to get the total height/width of the screen. If you divide them by 2, you get the middle of the screen.
Re: I have a question!
Just to add to what Plu said: If you ever want to find the center of the screen with an image, you would do the following:
Just in case you ever want to get the center of an image, there you go! Hope this helped!
Code: Select all
img = love.graphics.newImage("img.png")
centerX = ( ( love.graphics.getWidth()/2 )-( img:getWidth()/2 ) )
centerY = ( ( love.graphics.getHeight()/2 )-( img:getHeight()/2 ) )
"In those quiet moments, you come into my mind" - Liam Reilly
Re: I have a question!
Not to be nit-picky or anything but you should really give a less general name to your post than that. Instead of 'I have a question!' you could have called it something like 'Getting the center of the screen' or something like that.
Figured I would give you a heads up for future questions.
Also something else useful: getting the width of text and what not.
If you ever want to do this (and believe me, you most likely will), this is how you would go about doing it:
And there you have it! This is more than you probably wanted, but you never know if it might come in handy!
Figured I would give you a heads up for future questions.
Also something else useful: getting the width of text and what not.
If you ever want to do this (and believe me, you most likely will), this is how you would go about doing it:
Code: Select all
font = love.graphics.newFont('timesNewRomans.ttf', 32) --name of font, size
love.graphics.setFont(font)
text = 'Brought to you by XxFullMetalxX'
height = font:getHeight(text) --note that you don't actually have to put the argument text there since the font height will be the same. It's more of an organizational thing
width = font:getWidth(text) --You do need it for this one, however
center = { width/2, height/2 }
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Who is online
Users browsing this forum: Ahrefs [Bot] and 15 guests