QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Developers Corner > PSP Development, Hacks, and Homebrew > PSP Development Forum
The above video goes away if you are a member and logged in, so log in now!

Center Text

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 ...

Reply
 
LinkBack Thread Tools
Old 10-24-2005, 04:46 PM   #1
Advanced PSP Coder
 
Virtue's Avatar
 
Join Date: Oct 2005
Location: Down South
Posts: 426
Trader Feedback: 0
Default Center Text

How can you center text in Lua?

Lets say I have this:

screenrint(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]
Virtue is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-24-2005, 05:24 PM   #2
Premium Member
 
Lancer's Avatar
 
Join Date: Sep 2005
Posts: 44
Trader Feedback: 0
Default

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..
Lancer is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-24-2005, 05:43 PM   #3
Advanced PSP Coder
 
Virtue's Avatar
 
Join Date: Oct 2005
Location: Down South
Posts: 426
Trader Feedback: 0
Default

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]
Virtue is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-24-2005, 05:44 PM   #4
Advanced PSP Coder
 
Virtue's Avatar
 
Join Date: Oct 2005
Location: Down South
Posts: 426
Trader Feedback: 0
Default

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]
Virtue is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-24-2005, 05:49 PM   #5
NDS Mod
 
MagicianFB's Avatar
 
Join Date: Jul 2005
Location: w00+land
Posts: 645
Trader Feedback: 0
Default

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()
I think that would work.
__________________
"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..
MagicianFB is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-24-2005, 05:58 PM   #6
Advanced PSP Coder
 
Virtue's Avatar
 
Join Date: Oct 2005
Location: Down South
Posts: 426
Trader Feedback: 0
Default

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]
Virtue is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-24-2005, 06:00 PM   #7
Premium Member
 
Lancer's Avatar
 
Join Date: Sep 2005
Posts: 44
Trader Feedback: 0
Default

Aw... Beat me to it. =[ I'll post mine anyway.

Code:
function centertext(x, str)
	return x - ((string.len(str) * 8) / 2)
end
The function in use:

Code:
screen:print(centertext(100, "ZOMGHAX"), 200, "ZOMGHAX", white)
Of course, 100 could be changed to 480/2 and 200 could be changed to 272/2 to get the center of the screen.

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..
Lancer is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-24-2005, 06:02 PM   #8
NDS Mod
 
MagicianFB's Avatar
 
Join Date: Jul 2005
Location: w00+land
Posts: 645
Trader Feedback: 0
Default

Quote:
Originally Posted by Virtue
No errors, but doesn't work... hmm?
Oops, just edited it, it should work now.
__________________
"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]
MagicianFB is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-24-2005, 06:05 PM   #9
Advanced PSP Coder
 
Virtue's Avatar
 
Join Date: Oct 2005
Location: Down South
Posts: 426
Trader Feedback: 0
Default

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]
Virtue is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
center , text

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -8. The time now is 07:02 PM.



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2009, QJ.NET. All Rights Reserved.
Contact Us