![]() |
| Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact |
| ||||||
This is a discussion on Center Text within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; How can you center text in Lua? Lets say I have this: screen rint(x, 240, message) if msg = 1 ...
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 |
![]() Advanced PSP Coder
|
How can you center text in Lua?
Lets say I have this: screen rint(x, 240, message)if msg = 1 then message = "HELLO!" end if msg = 2 then message = "HELLO! I AM SO FRIGGEN COOL HAHA" end And it's in a loop, where message variable can change at any moment, how can I get it to print the message in the middle, so its always even? Thanks.
__________________
[center][COLOR=Green][B]- PM Me if you need help with anything - [/B] [/COLOR] [B][SIZE=3][COLOR=DarkOrange][U]Homebrew I've Made[/U][/COLOR][/SIZE][/B] [B]Applications: [URL=http://files.pspupdates.qj.net/cgi-bin/cfiles.cgi?0,0,0,0,17,1667]PSP Alarm v0.5[/URL] [/b] [B]Games: [URL=http://files.pspupdates.qj.net/cgi-bin/cfiles.cgi?0,0,0,0,12,1669] Virtual Escape DEMO[/URL] [w/ Lancer] [URL=http://files.pspupdates.qj.net/cgi-bin/cfiles.cgi?0,0,0,0,12,1577]PSP Dodge v1.0[/URL][/b] [img]http://img517.imageshack.us/img517/4735/sig3qu.jpg[/img][/center] |
|
|
|
|
|
#2 |
![]() Premium Member
|
Well, I think there is a function to get the length of a string. So if you could find the size of each character, multiply them by the length of the string, then divide that number by two, you would get half the length of the string. Subtract that from the original position and it will center it on the original position... I think... I got 1 hour of sleep last night... >_>
Edit: I think I'm gonna code this, it sounds like fun. Expect another reply in a while. =P
__________________
[IMG]http://i43.photobucket.com/albums/e361/Lancer2D/signatures/lancerghost.png[/IMG] Last edited by Lancer; 10-24-2005 at 05:31 PM.. |
|
|
|
|
|
#3 |
![]() Advanced PSP Coder
|
Ahh dude, thanks sooo much. I mean, I had teh same idea if their wasn't a function to do this automatically, but if you code the example it will be easier for me to implement it
![]() I know in most langauges it would be like this to get the lenght of a string: lenofmsg = Len(message) Not sure about Lua
__________________
[center][COLOR=Green][B]- PM Me if you need help with anything - [/B] [/COLOR] [B][SIZE=3][COLOR=DarkOrange][U]Homebrew I've Made[/U][/COLOR][/SIZE][/B] [B]Applications: [URL=http://files.pspupdates.qj.net/cgi-bin/cfiles.cgi?0,0,0,0,17,1667]PSP Alarm v0.5[/URL] [/b] [B]Games: [URL=http://files.pspupdates.qj.net/cgi-bin/cfiles.cgi?0,0,0,0,12,1669] Virtual Escape DEMO[/URL] [w/ Lancer] [URL=http://files.pspupdates.qj.net/cgi-bin/cfiles.cgi?0,0,0,0,12,1577]PSP Dodge v1.0[/URL][/b] [img]http://img517.imageshack.us/img517/4735/sig3qu.jpg[/img][/center] |
|
|
|
|
|
#4 |
![]() Advanced PSP Coder
|
Also lancer, do you have aim or msn?
__________________
[center][COLOR=Green][B]- PM Me if you need help with anything - [/B] [/COLOR] [B][SIZE=3][COLOR=DarkOrange][U]Homebrew I've Made[/U][/COLOR][/SIZE][/B] [B]Applications: [URL=http://files.pspupdates.qj.net/cgi-bin/cfiles.cgi?0,0,0,0,17,1667]PSP Alarm v0.5[/URL] [/b] [B]Games: [URL=http://files.pspupdates.qj.net/cgi-bin/cfiles.cgi?0,0,0,0,12,1669] Virtual Escape DEMO[/URL] [w/ Lancer] [URL=http://files.pspupdates.qj.net/cgi-bin/cfiles.cgi?0,0,0,0,12,1577]PSP Dodge v1.0[/URL][/b] [img]http://img517.imageshack.us/img517/4735/sig3qu.jpg[/img][/center] |
|
|
|
|
|
#5 |
![]() NDS Mod
|
Code:
System.usbDiskModeActivate() red = Color.new(255, 0, 0) function centerText(where, y, text, color) where:print((screen:width()/2)-((string.len(text)/2)*8), y, text, color) end centerText(screen, 240, "HELLO!!!", red) screen:flip() repeat pad = Controls.read() until pad:cross()
__________________
"15% percent of programing is creating a program, 85% percent is getting it to work like it should." - Me [URL=http://www.mozilla.org/products/firefox/][IMG]http://img439.imageshack.us/img439/5667/getfirefox0sr.png[/IMG][/URL] Last edited by MagicianFB; 10-24-2005 at 06:02 PM.. |
|
|
|
|
|
#6 |
![]() Advanced PSP Coder
|
No errors, but doesn't work... hmm?
__________________
[center][COLOR=Green][B]- PM Me if you need help with anything - [/B] [/COLOR] [B][SIZE=3][COLOR=DarkOrange][U]Homebrew I've Made[/U][/COLOR][/SIZE][/B] [B]Applications: [URL=http://files.pspupdates.qj.net/cgi-bin/cfiles.cgi?0,0,0,0,17,1667]PSP Alarm v0.5[/URL] [/b] [B]Games: [URL=http://files.pspupdates.qj.net/cgi-bin/cfiles.cgi?0,0,0,0,12,1669] Virtual Escape DEMO[/URL] [w/ Lancer] [URL=http://files.pspupdates.qj.net/cgi-bin/cfiles.cgi?0,0,0,0,12,1577]PSP Dodge v1.0[/URL][/b] [img]http://img517.imageshack.us/img517/4735/sig3qu.jpg[/img][/center] |
|
|
|
|
|
#7 |
![]() Premium Member
|
Aw... Beat me to it. =[ I'll post mine anyway.
Code:
function centertext(x, str) return x - ((string.len(str) * 8) / 2) end Code:
screen:print(centertext(100, "ZOMGHAX"), 200, "ZOMGHAX", white) Edit: You can get ahold of me on AIM, my username is LancerY. Also, the reason his code doesnt work is because his print and screen:flip aren't in a loop.
__________________
[IMG]http://i43.photobucket.com/albums/e361/Lancer2D/signatures/lancerghost.png[/IMG] Last edited by Lancer; 10-24-2005 at 06:05 PM.. |
|
|
|
|
|
#8 | |
![]() NDS Mod
|
Quote:
__________________
"15% percent of programing is creating a program, 85% percent is getting it to work like it should." - Me [URL=http://www.mozilla.org/products/firefox/][IMG]http://img439.imageshack.us/img439/5667/getfirefox0sr.png[/IMG][/URL] |
|
|
|
|
|
|
#9 |
![]() Advanced PSP Coder
|
Thanks so much FB.. <3
He got it working
__________________
[center][COLOR=Green][B]- PM Me if you need help with anything - [/B] [/COLOR] [B][SIZE=3][COLOR=DarkOrange][U]Homebrew I've Made[/U][/COLOR][/SIZE][/B] [B]Applications: [URL=http://files.pspupdates.qj.net/cgi-bin/cfiles.cgi?0,0,0,0,17,1667]PSP Alarm v0.5[/URL] [/b] [B]Games: [URL=http://files.pspupdates.qj.net/cgi-bin/cfiles.cgi?0,0,0,0,12,1669] Virtual Escape DEMO[/URL] [w/ Lancer] [URL=http://files.pspupdates.qj.net/cgi-bin/cfiles.cgi?0,0,0,0,12,1577]PSP Dodge v1.0[/URL][/b] [img]http://img517.imageshack.us/img517/4735/sig3qu.jpg[/img][/center] |
|
|
|
![]() |
| Tags |
| center , text |
| Thread Tools | |
|
|