Jump to content

[QUESTION] responsive dx drawing

Recommended Posts

if getElementData( localPlayer,"duty_admin" )  == 1  then
   dxDrawImage(1645, 500, 64, 64, "images/hud/adm_on.png")
   table.insert(tooltips, "adminonduty")

Hello guys, so i`m learning slowly a lot of stuff when u answer my questions, now i got a problem, a bigger one i think, i draw that image but it shows different on other resolutions, can u please tell me how to do it or show me an example because i`m a beginner.. i tried following other scaling on all resolutions but i think they are no use, i want that icon basically to stand in the right middle screen..



Link to post
  • Scripting Moderators
1 minute ago, LeonardoWilliams said:

I need to calculate it for every resolution ?


  • Thanks 1
Link to post

Can someone please give me an example on how to draw an image on all resolutions positioned right in the right middle , i tried to do it myself but it s just too much to understand by just reading, i need to see a script like that to understand it i think, please

Link to post
  • Moderators
-- Okay, so you have to pick a base resolution, you should choose what you use.
local baseWidth, baseHeight = 1920, 1080 -- I pick fullhd
-- We'll need the current resolution
local screenWidth, screenHeight = guiGetScreenSize() -- imageine this is 1366x768 now
-- and now we have to calculate the difference ratio between the base- and current resolution
local xDiffRatio, yDiffRatio = screenWidth/baseWidth, screenHeight/baseHeight -- this will be: (1920/1366=1.40556) and (1080/768=1.40625)
-- then we have to multiply every (X-coordinate and Width with 'xDiffRatio') and every (Y-coordinate and Height with 'yDiffRatio') -> this will resize everything (ofcourse if base- and current resolution is equals, then it doesn't change)

-- now draw the image
local imageX, imageY = 1645, 500
local imageWidth, imageHeight = 64, 64
-- miltiply values with the right ratio
dxDrawImage(imageX*xDiffRatio, imageY*yDiffRatio, imageWidth*xDiffRatio, imageHeight*yDiffRatio, "images/hud/adm_on.png")

-- NOTE: you can make your life easier if you create a "custom" dxDrawImage event what do the math for you, call it 'myDrawImage'
function myDrawImage(x, y, width, height, ...) -- three dot means (...) every parameter after 4th, this is a "magic parameter"
    dxDrawImage(x*xDiffRatio, y*yDiffRatio, width*xDiffRatio, height*yDiffRatio, ...) -- and don't forget the dots
-- and now you can use your new function
myDrawImage(imageX, imageY, imageWidth, imageHeight, "images/hud/adm_on.png")


  • Thanks 1
Link to post
  • Moderators
12 minutes ago, LeonardoWilliams said:

Thank you so much Patrick, you helped me again a lot!! You are the best :D❤️ 

Of course this code doesn't handle 4:3 resolutions like 800x600, and HUDs will be stretched.
You can find solution for that in the tutorial what srslyyyy linked above.

  • Thanks 1
Link to post
  • Patrick changed the title to [QUESTION] responsive dx drawing

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...