Wei Posted February 18, 2014 Posted February 18, 2014 example = { {"test1"}; {"test2"}; } function draw() for index, value in ipairs (example) do dxDrawRectangle( pos1, pos2, 100, 50 ) end end addEventHandler("onClientRender", root, draw) Can someone explain me how I can get pos1 and pos2 to allways be in middle of screen ? I loosing my mind with this calculations -.- Thanks, Wei. Diet with russian vodka, lose 3 days in one week !
Castillo Posted February 18, 2014 Posted February 18, 2014 local sx, sy = guiGetScreenSize ( ) local example = { { "test1" }, { "test2" } } function draw ( ) local width, height = 100, 50 local x, y = ( sx / 2 - width / 2 ), ( sy / 2 - height / 2 ) for _, value in ipairs ( example ) do dxDrawRectangle ( x, y, width, height ) end end addEventHandler ( "onClientRender", root, draw ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Wei Posted February 18, 2014 Author Posted February 18, 2014 I'm sorry I forgot to mention to test1 and test2 would be seperated by 10px. Diet with russian vodka, lose 3 days in one week !
Castillo Posted February 18, 2014 Posted February 18, 2014 You mean the "y" separated by 10px? San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Wei Posted February 18, 2014 Author Posted February 18, 2014 yes but it would be still in middle of screen Edit* I mean like there would be 2 seperated rectangles that will together be in middle of screen Diet with russian vodka, lose 3 days in one week !
Castillo Posted February 18, 2014 Posted February 18, 2014 local sx, sy = guiGetScreenSize ( ) local example = { { "test1" }, { "test2" } } function draw ( ) local width, height = 100, 50 local x, y = ( sx / 2 - width / 2 ), ( sy / 2 - height / 2 ) for _, value in ipairs ( example ) do dxDrawRectangle ( x, y, width, height ) y = ( y + 10 ) end end addEventHandler ( "onClientRender", root, draw ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
MTA Team 0xCiBeR Posted February 18, 2014 MTA Team Posted February 18, 2014 Wouldn't That make the Y pos +10 on every frame? EDIT: My Bad DevOps Engineer, Cloud Advocate & Security Engineer(Red Team) | Coffee, Containers & Burp
Wei Posted February 18, 2014 Author Posted February 18, 2014 Thanks Solidsnake! Diet with russian vodka, lose 3 days in one week !
Castillo Posted February 18, 2014 Posted February 18, 2014 You're welcome. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Moderators Citizen Posted February 18, 2014 Moderators Posted February 18, 2014 (edited) Hummm okay, I'm a bit late again but the code of Solidsnake doesn't center all rectangle as a whole. So if you add 5 rectangles in your table, then the 1st one will still be rendered from the middle and the last rectangles will probably rendered out of the screen. Here is my version with a screenshot with explainations: local sx, sy = guiGetScreenSize ( ) local example = { { "test1" }, { "test2" } } function draw ( ) local width, height = 100, 50 local offsetY = 10 -- seperation between each rectangles local totalHeight = (50+offsetY)*(#example)-offsetY --(-offsetY to remove seperation of the last rectangle) local x = ( sx/2 - width/2 ) for k, value in ipairs ( example ) do local y = (sy/2 - totalHeight/2) + (height+offsetY) * (k-1) dxDrawRectangle ( x, y, width, height ) end end addEventHandler ( "onClientRender", root, draw ) The result with extra explainations: EDIT: Alright ! seems that the image can't be displayed from gyazo, is there a whitelist on that forum ? I'm gonna upload it somewhere else. EDIT2: Changed img tag Edited February 18, 2014 by Guest The rEvolution is coming ...
Wei Posted February 18, 2014 Author Posted February 18, 2014 I've noticed, thanks Citizen for explanation! Diet with russian vodka, lose 3 days in one week !
Moderators Citizen Posted February 18, 2014 Moderators Posted February 18, 2014 No problem, still don't know what you really wanted though The rEvolution is coming ...
Wei Posted February 18, 2014 Author Posted February 18, 2014 No problem, still don't know what you really wanted though I am making login gui like some multigamemode servers use to select gamemode I will use Login, Register and Forgot password... Diet with russian vodka, lose 3 days in one week !
Moderators Citizen Posted February 18, 2014 Moderators Posted February 18, 2014 Yeah okay, so you wanted to center all rectangles to the middle as a whole (like if it was 1 block) like I did ? The rEvolution is coming ...
Wei Posted February 18, 2014 Author Posted February 18, 2014 Yeah okay, so you wanted to center all rectangles to the middle as a whole (like if it was 1 block) like I did ? exactly Diet with russian vodka, lose 3 days in one week !
Moderators Citizen Posted February 18, 2014 Moderators Posted February 18, 2014 k, good luck with your project then The rEvolution is coming ...
Wei Posted February 18, 2014 Author Posted February 18, 2014 Thanks Diet with russian vodka, lose 3 days in one week !
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