AlvarO Posted October 3, 2015 Share Posted October 3, 2015 Hey all, I was scripting a Login when a friend joined, told me that texts are showing up of the rectangles, but for me it is inside of them, please tell me whats wrong: local x, y = guiGetScreenSize() local px, py = 1980, 1080 local sx, sy = (x/px), (x/py) local start = getTickCount() local font = dxCreateFont("font.ttf", 52, false) function drawingLogin() --Animaciones local now = getTickCount() local elapsedTime = now - start local endTime = start + 1000 local duration = endTime - start local progress = elapsedTime / duration local x1, y1, z1 = interpolateBetween(x/2-200, y/7, 0, x/2-200, y/3.5, 0, progress, "OutBounce") local x2, y2, z2 = interpolateBetween(x/2+93, y/2-65, 0, x/2+93, y/2-33, 0, progress, "OutBounce") dxDrawImage(0, 0, x, y, "img/background.png") dxDrawRectangle(x1-450, y1+200, 400, 50, tocolor(255, 255, 255, 75)) dxDrawRectangle(x1+400, y1+200, 400, 50, tocolor(255, 255, 255, 75)) dxDrawRectangle(x1, y1+200, 65, 50, tocolor(255, 255, 255, 75)) dxDrawRectangle(x1+285, y1+200, 65, 50, tocolor(255, 255, 255, 75)) dxDrawRectangle(x1, y1+275, 350, 50, rectanglecchanger1) dxDrawImage(x2, y2, 50, 50, "img/login.png") dxDrawImage(x2-285, y2, 50, 50, "img/register.png") dxDrawText("SIGN IN", x1-310, y1-320, x, y, tocolor(255, 255, 255, 255), 0.4, font, "left", "center", false, false, false, true, true) dxDrawText("ADD NEW ACCOUNT", x1+475, y1-320, x, y, tocolor(255, 255, 255, 255), 0.4, font, "left", "center", false, false, false, true, true) dxDrawText("PLAY AS GUEST", x1+107, y1-175, x, y, tocolor(255, 255, 255, 255), 0.3, font, "left", "center", false, false, false, true, true) showChat(false) showCursor(true) end addEventHandler("onClientRender", root, drawingLogin) function playAsGuest (button, state, absoluteX, absoluteY, wx, wy, wz, clickedElement) if state == "down" then if isMouseInPosition (x/2-200, y/2+43, 350, 50) then removeEventHandler("onClientRender", root, drawingLogin) showChat(true) showCursor(false) end end end addEventHandler ("onClientClick", getRootElement(), playAsGuest) function cambiarColor1() if isMouseInPosition(x/2-200, y/2+43, 350, 50) then rectanglecchanger1 = tocolor(255, 255, 255, 50) else rectanglecchanger1 = tocolor(255, 255, 255, 125) end end addEventHandler("onClientRender", root, cambiarColor1) function isMouseInPosition (x, y, width, height) if (not isCursorShowing ()) then return false end local sx, sy = guiGetScreenSize () local cx, cy = getCursorPosition () local cx, cy = (cx * sx), (cy*sy) if (cx >= x and cx <= x + width) and (cy >= y and cy <= y + height) then return true else return false end end Link to comment
Dealman Posted October 3, 2015 Share Posted October 3, 2015 Well, first of all it's 1920x1080 and not 1980x1080. Secondly, I'd suggest you follow this method instead; I use a website where you can run Lua code to make the process very fast and straight forward, since doing it all manually is a very tedious process. Especially with DX functions. Simply paste this code(into the website linked above) and enter the appropriate values. Then copy the output and you're golden. local sX, sY, wX, hY = 480, 240, 969, 570; -- Paste the absolute values here local sourceWidth = 1920; -- Change those to the source values. local sourceHeight = 1080; -- Change those to the source values. local nSX, nSY, nWX, nHY = (sX/sourceWidth), (sY/sourceHeight), (wX/sourceWidth), (hY/sourceHeight); for i=0, 47 do print(""); -- This is just to clear the print window, so you don't get confused what to copy. end print(tostring(nSX).."*screenX, "..tostring(nSY).."*screenY, "..tostring(nWX).."*screenX, "..tostring(nHY).."*screenY"); Thirdly, the reason it doesn't look the same for you is because of the way you're doing the math. A 200 pixel transition is less on a 1920x1080 resolution than on for example a 1280x720 resolution. Link to comment
Dealman Posted October 3, 2015 Share Posted October 3, 2015 Could you post the new, updated code? Link to comment
AlvarO Posted October 4, 2015 Author Share Posted October 4, 2015 (edited) local x, y, sx, sy = 1920, 1080 , 1920, 1080 local sourceWidth = 1980 local sourceHeight = 1080 local nSX, nSY, nWX, nHY = (x/sourceWidth), (y/sourceHeight), (sx/sourceWidth), (sy/sourceHeight) local start = getTickCount() local font = dxCreateFont("font.ttf", 52, false) function drawingLogin() --Animaciones local now = getTickCount() local elapsedTime = now - start local endTime = start + 1000 local duration = endTime - start local progress = elapsedTime / duration local x1, y1, z1 = interpolateBetween(x/2-200, y/7, 0, x/2-200, y/3.5, 0, progress, "OutBounce") local x2, y2, z2 = interpolateBetween(x/2+93, y/2-65, 0, x/2+93, y/2-33, 0, progress, "OutBounce") dxDrawImage(0, 0, x, y, "img/background.png") dxDrawRectangle(x1-450, y1+200, 400, 50, tocolor(255, 255, 255, 75)) dxDrawRectangle(x1+400, y1+200, 400, 50, tocolor(255, 255, 255, 75)) dxDrawRectangle(x1, y1+200, 65, 50, tocolor(255, 255, 255, 75)) dxDrawRectangle(x1+285, y1+200, 65, 50, tocolor(255, 255, 255, 75)) dxDrawRectangle(x1, y1+275, 350, 50, rectanglecchanger1) dxDrawImage(x2, y2, 50, 50, "img/login.png") dxDrawImage(x2-285, y2, 50, 50, "img/register.png") dxDrawText("SIGN IN", x1-310, y1-320, x, y, tocolor(255, 255, 255, 255), 0.4, font, "left", "center", false, false, false, true, true) dxDrawText("ADD NEW ACCOUNT", x1+475, y1-320, x, y, tocolor(255, 255, 255, 255), 0.4, font, "left", "center", false, false, false, true, true) dxDrawText("PLAY AS GUEST", x1+107, y1-175, x, y, tocolor(255, 255, 255, 255), 0.3, font, "left", "center", false, false, false, true, true) --Varios showChat(false) showCursor(true) end addEventHandler("onClientRender", root, drawingLogin) function playAsGuest (button, state, absoluteX, absoluteY, wx, wy, wz, clickedElement) if state == "down" then if isMouseInPosition (x/2-200, y/2+43, 350, 50) then removeEventHandler("onClientRender", root, drawingLogin) showChat(true) showCursor(false) end end end addEventHandler ("onClientClick", getRootElement(), playAsGuest) --Cambiar function cambiarColor1() if isMouseInPosition(x/2-200, y/2+43, 350, 50) then rectanglecchanger1 = tocolor(255, 255, 255, 50) else rectanglecchanger1 = tocolor(255, 255, 255, 125) end end addEventHandler("onClientRender", root, cambiarColor1) --Usefuls function isMouseInPosition (x, y, width, height) if (not isCursorShowing ()) then return false end local sx, sy = guiGetScreenSize () local cx, cy = getCursorPosition () local cx, cy = (cx * sx), (cy*sy) if (cx >= x and cx <= x + width) and (cy >= y and cy <= y + height) then return true else return false end end Edited October 4, 2015 by Guest Link to comment
AlvarO Posted October 4, 2015 Author Share Posted October 4, 2015 local x, y, sx, sy = 1920, 1080 , 1920, 1080 local sourceWidth = 1980 local sourceHeight = 1080 local nSX, nSY, nWX, nHY = (x/sourceWidth), (y/sourceHeight), (sx/sourceWidth), (sy/sourceHeight) local start = getTickCount() local font = dxCreateFont("font.ttf", 52, false) function drawingLogin() --Animaciones local now = getTickCount() local elapsedTime = now - start local endTime = start + 1000 local duration = endTime - start local progress = elapsedTime / duration local x1, y1, z1 = interpolateBetween(x/2-200, y/7, 0, x/2-200, y/3.5, 0, progress, "OutBounce") local x2, y2, z2 = interpolateBetween(x/2+93, y/2-65, 0, x/2+93, y/2-33, 0, progress, "OutBounce") dxDrawImage(0, 0, x, y, "img/background.png") dxDrawRectangle(x1-450, y1+200, 400, 50, tocolor(255, 255, 255, 75)) dxDrawRectangle(x1+400, y1+200, 400, 50, tocolor(255, 255, 255, 75)) dxDrawRectangle(x1, y1+200, 65, 50, tocolor(255, 255, 255, 75)) dxDrawRectangle(x1+285, y1+200, 65, 50, tocolor(255, 255, 255, 75)) dxDrawRectangle(x1, y1+275, 350, 50, rectanglecchanger1) dxDrawImage(x2, y2, 50, 50, "img/login.png") dxDrawImage(x2-285, y2, 50, 50, "img/register.png") dxDrawText("SIGN IN", x1-310, y1-320, x, y, tocolor(255, 255, 255, 255), 0.4, font, "left", "center", false, false, false, true, true) dxDrawText("ADD NEW ACCOUNT", x1+475, y1-320, x, y, tocolor(255, 255, 255, 255), 0.4, font, "left", "center", false, false, false, true, true) dxDrawText("PLAY AS GUEST", x1+107, y1-175, x, y, tocolor(255, 255, 255, 255), 0.3, font, "left", "center", false, false, false, true, true) --Varios showChat(false) showCursor(true) end addEventHandler("onClientRender", root, drawingLogin) function playAsGuest (button, state, absoluteX, absoluteY, wx, wy, wz, clickedElement) if state == "down" then if isMouseInPosition (x/2-200, y/2+43, 350, 50) then removeEventHandler("onClientRender", root, drawingLogin) showChat(true) showCursor(false) end end end addEventHandler ("onClientClick", getRootElement(), playAsGuest) --Cambiar function cambiarColor1() if isMouseInPosition(x/2-200, y/2+43, 350, 50) then rectanglecchanger1 = tocolor(255, 255, 255, 50) else rectanglecchanger1 = tocolor(255, 255, 255, 125) end end addEventHandler("onClientRender", root, cambiarColor1) --Usefuls function isMouseInPosition (x, y, width, height) if (not isCursorShowing ()) then return false end local sx, sy = guiGetScreenSize () local cx, cy = getCursorPosition () local cx, cy = (cx * sx), (cy*sy) if (cx >= x and cx <= x + width) and (cy >= y and cy <= y + height) then return true else return false end end Link to comment
Dealman Posted October 4, 2015 Share Posted October 4, 2015 You didn't read my post at all did you? Go to the website I linked in my quote, there you can execute Lua code, whether for testing or whatnot. Post this code in there; local sX, sY, wX, hY = 480, 240, 969, 570; -- Paste the absolute values here local sourceWidth = 1920; -- Change those to the source values. local sourceHeight = 1080; -- Change those to the source values. local nSX, nSY, nWX, nHY = (sX/sourceWidth), (sY/sourceHeight), (wX/sourceWidth), (hY/sourceHeight); for i=0, 47 do print(""); -- This is just to clear the print window, so you don't get confused what to copy. end print(tostring(nSX).."*screenX, "..tostring(nSY).."*screenY, "..tostring(nWX).."*screenX, "..tostring(nHY).."*screenY"); Then replace this local sX, sY, wX, hY = 480, 240, 969, 570; -- Paste the absolute values here With whatever absolute values you have. Do this for each rectangle, text and whatnot. When you run the code on that website it will return the relative value - which is what you want. It's simply a matter of copy and paste. Also you're still trying to use 1980x1080. It should be 1920x1080. Link to comment
jingzhi Posted November 19, 2015 Share Posted November 19, 2015 Hey all, I was scripting a Login when a friend joined, told me that texts are showing up of the rectangles, but for me it is inside of them, please tell me whats wrong: local x, y = guiGetScreenSize() local px, py = 1980, 1080 local sx, sy = (x/px), (x/py) local start = getTickCount() local font = dxCreateFont("font.ttf", 52, false) function drawingLogin() --Animaciones local now = getTickCount() local elapsedTime = now - start local endTime = start + 1000 local duration = endTime - start local progress = elapsedTime / duration local x1, y1, z1 = interpolateBetween(x/2-200, y/7, 0, x/2-200, y/3.5, 0, progress, "OutBounce") local x2, y2, z2 = interpolateBetween(x/2+93, y/2-65, 0, x/2+93, y/2-33, 0, progress, "OutBounce") dxDrawImage(0, 0, x, y, "img/background.png") dxDrawRectangle(x1-450, y1+200, 400, 50, tocolor(255, 255, 255, 75)) dxDrawRectangle(x1+400, y1+200, 400, 50, tocolor(255, 255, 255, 75)) dxDrawRectangle(x1, y1+200, 65, 50, tocolor(255, 255, 255, 75)) dxDrawRectangle(x1+285, y1+200, 65, 50, tocolor(255, 255, 255, 75)) dxDrawRectangle(x1, y1+275, 350, 50, rectanglecchanger1) dxDrawImage(x2, y2, 50, 50, "img/login.png") dxDrawImage(x2-285, y2, 50, 50, "img/register.png") dxDrawText("SIGN IN", x1-310, y1-320, x, y, tocolor(255, 255, 255, 255), 0.4, font, "left", "center", false, false, false, true, true) dxDrawText("ADD NEW ACCOUNT", x1+475, y1-320, x, y, tocolor(255, 255, 255, 255), 0.4, font, "left", "center", false, false, false, true, true) dxDrawText("PLAY AS GUEST", x1+107, y1-175, x, y, tocolor(255, 255, 255, 255), 0.3, font, "left", "center", false, false, false, true, true) showChat(false) showCursor(true) end addEventHandler("onClientRender", root, drawingLogin) function playAsGuest (button, state, absoluteX, absoluteY, wx, wy, wz, clickedElement) if state == "down" then if isMouseInPosition (x/2-200, y/2+43, 350, 50) then removeEventHandler("onClientRender", root, drawingLogin) showChat(true) showCursor(false) end end end addEventHandler ("onClientClick", getRootElement(), playAsGuest) function cambiarColor1() if isMouseInPosition(x/2-200, y/2+43, 350, 50) then rectanglecchanger1 = tocolor(255, 255, 255, 50) else rectanglecchanger1 = tocolor(255, 255, 255, 125) end end addEventHandler("onClientRender", root, cambiarColor1) function isMouseInPosition (x, y, width, height) if (not isCursorShowing ()) then return false end local sx, sy = guiGetScreenSize () local cx, cy = getCursorPosition () local cx, cy = (cx * sx), (cy*sy) if (cx >= x and cx <= x + width) and (cy >= y and cy <= y + height) then return true else return false end end You can simply use the ratio between Full HD screen resolution and player's resolution and multiply by this ratio in every variable in the dxDraw Functions. Link to comment
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