BiSolpos Posted October 9, 2023 Share Posted October 9, 2023 Hello everyone, I need help with something, I'm creating a bar for car fuel The bar is fine in my resolution, but in some resolutions it is like the image below https://imgur.com/a/ZGD8NDT local screenX, screenY = guiGetScreenSize() function ScaleY(value) return value / (900 / screenY) end function Speedo() local vehicle = getPedOccupiedVehicle(localPlayer) if vehicle then local fuel = tonumber(getElementData(vehicle, "fuel")) dxDrawImageSection(screenX - ScaleY(289), screenY - ScaleY(19), ScaleY(47), ScaleY(-(123*(fuel/100))), 0, 0, ScaleY(47), ScaleY(-(123*(fuel/100))),"fuel.png", 0, 0, 0, tocolor(2,153,0,255), false) end end addEventHandler("onClientRender", getRootElement(), Speedo) Link to comment
Moderators IIYAMA Posted October 9, 2023 Moderators Share Posted October 9, 2023 -- Run this one time local fuelImage = dxCreateTexture ("fuel.png", "argb", true, "clamp") And: dxDrawImageSection(screenX - ScaleY(289), screenY - ScaleY(19), ScaleY(47), ScaleY(-(123*(fuel/100))), 0, 0, ScaleY(47), ScaleY(-(123*(fuel/100))), fuelImage , 0, 0, 0, tocolor(2,153,0,255), false) Link to comment
alex17" Posted October 9, 2023 Share Posted October 9, 2023 (edited) The arguments u: the absolute X coordinate of the top left corner of the section which should be drawn from image v: the absolute Y coordinate of the top left corner of the section which should be drawn from image usize: the absolute width of the image section vsize: the absolute height of the image section must be worked based on the original size in pixels of the image and not based on the size it will have on the screen local imgW, imgH = 200, 150 dxDrawImageSection(screenX - ScaleY(289), screenY - ScaleY(19), ScaleY(47), ScaleY(-(123*(fuel/100))), 0, 0, imgW, imgW * (fuel/100),"fuel.png", 0, 0, 0, tocolor(2,153,0,255), false) To get the image size, right click on the image / properties / details / see dimensions Edited October 9, 2023 by alex17" 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