.:HyPeX:. Posted February 13, 2015 Posted February 13, 2015 Hello, i've got a question, how can i invert my text size? To clarify these are my maths: local text = "~HyPeX~ASdasdasd" local size = dxGetTextWidth(text,1,"default") local max = 100 local size = size/max local tsize = size * -4+4 outputConsole(tsize) So far, it works kinda good, but the sizes vary too much. I.e: big texts are excesively small and small texts are excesively big.. My ingame nick is ~HyPeX~ BF3 Gamemode Progress: ~30% - Currently working on AI & MapManager
xXMADEXx Posted February 14, 2015 Posted February 14, 2015 What exactly are you trying to do? The Ultimate Lua Tutorial! | MTA PHP SDK
.:HyPeX:. Posted February 14, 2015 Author Posted February 14, 2015 What exactly are you trying to do? Make the text always fit in a 100 pixel width space, having the size 1 as maximum and getting smaller if it is too big. My ingame nick is ~HyPeX~ BF3 Gamemode Progress: ~30% - Currently working on AI & MapManager
xXMADEXx Posted February 14, 2015 Posted February 14, 2015 What exactly are you trying to do? Make the text always fit in a 100 pixel width space, having the size 1 as maximum and getting smaller if it is too big. I'm not sure how the math wouldbe, but you could use a while loop, something like this: local text = "~HyPeX~ASdasdasd" local size = dxGetTextWidth(text,1,"default") local tSize = 1; if ( size < 100 ) then while ( size < 100 ) do tSize = tSize + 0.5; size = dxGetTextWidth(text,tSize,"default") end elseif ( size > 100 ) then while ( size > 100 ) then tSize = tSize - 0.5; size = dxGetTextWidth(text,tSize,"default") end end outputConsole ( tSize ); The Ultimate Lua Tutorial! | MTA PHP SDK
.:HyPeX:. Posted February 14, 2015 Author Posted February 14, 2015 What exactly are you trying to do? Make the text always fit in a 100 pixel width space, having the size 1 as maximum and getting smaller if it is too big. I'm not sure how the math wouldbe, but you could use a while loop, something like this: local text = "~HyPeX~ASdasdasd" local size = dxGetTextWidth(text,1,"default") local tSize = 1; if ( size < 100 ) then while ( size < 100 ) do tSize = tSize + 0.5; size = dxGetTextWidth(text,tSize,"default") end elseif ( size > 100 ) then while ( size > 100 ) then tSize = tSize - 0.5; size = dxGetTextWidth(text,tSize,"default") end end outputConsole ( tSize ); Would that work in a clientRender loop, or is it adviced to do it before? My ingame nick is ~HyPeX~ BF3 Gamemode Progress: ~30% - Currently working on AI & MapManager
JR10 Posted February 14, 2015 Posted February 14, 2015 If you don't use onClientRender, whenever the text changes the size won't be updated. Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
.:HyPeX:. Posted February 14, 2015 Author Posted February 14, 2015 If you don't use onClientRender, whenever the text changes the size won't be updated. What i was asking was if it was ideal in performance terms, i could add a check to see if the text changes and then do the size update, my question was if it was worth the work. (But i guess not so much since its client side stuff) My ingame nick is ~HyPeX~ BF3 Gamemode Progress: ~30% - Currently working on AI & MapManager
JR10 Posted February 15, 2015 Posted February 15, 2015 The check would be better, but it probably wouldn't be noticeable. Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
.:HyPeX:. Posted February 16, 2015 Author Posted February 16, 2015 The check would be better, but it probably wouldn't be noticeable. Great, Thanks! Already tested both, didnt see any difference at all. My ingame nick is ~HyPeX~ BF3 Gamemode Progress: ~30% - Currently working on AI & MapManager
JR10 Posted February 16, 2015 Posted February 16, 2015 You won't because it's a small portion of text and the check is done once per client render. Imagine a scenario with a large string and a loop, this can be costly. Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now