WhoAmI Posted March 4, 2014 Share Posted March 4, 2014 Hi guys. I'm about to do a radar. I got a map 6000px x 6000px. How could I get the real position in pixels? Well, I saw a fe topics and I got this code. local mapImgWidth, mapImgHeight = 6000, 6000 local ratioX, ratioY = --[[value here]], --[[value here]] local x, y = getElementPosition ( localPlayer ) local tempMapX, tempMapY = x * ratioX, y * ratioY --the position in pixels on your map file ( with the middle of this file as origin (0, 0) ) local mapX, mapY = tempMapX + mapImgWidth / 2, tempMapY + mapImgHeight / 2 --the position in pixels on your map file ( with the upper left corner of this image as origin (0, 0) ) --so now we have the real position in pixels, we draw the the map: dxDrawImageSection ( radarX, radarY, radarWidth, radarHeight, mapX - mapWidth / 2, mapY - mapWidth / 2, mapX + mapWidth / 2, mapY + mapWidth / 2, "map.jpg" ) But I don't really now what is this ratioX, ratioY value and from what I could get mapWidth? Link to comment
Anubhav Posted March 4, 2014 Share Posted March 4, 2014 Its 600x600 image height and width. Write ratioX, ratioY of the picture. Link to comment
WhoAmI Posted March 4, 2014 Author Share Posted March 4, 2014 What? I don't understand. The image is 6000 x 6000 (6 tousand). And mapWidth in this code? Link to comment
WhoAmI Posted March 4, 2014 Author Share Posted March 4, 2014 Well, I got this: http://snag.gy/eNMle.jpg Anyone can help me with this code, and let me try to understand it? screenX, screenY = guiGetScreenSize ( ) radarWidth, radarHeight = 300, 200 radarX, radarY = 50, screenY - ( radarHeight + 50 ) mapImgWidth, mapImgHeight = 6000, 6000 mapWidth = 3000 ratioX, ratioY = mapImgWidth / mapImgHeight, mapImgWidth / mapImgHeight showPlayerHudComponent ( "radar", false ) function drawRadar ( ) local x, y = getElementPosition ( localPlayer ) local tempMapX, tempMapY = x * ratioX, y * ratioY --the position in pixels on your map file ( with the middle of this file as origin (0, 0) ) local mapX, mapY = tempMapX + mapImgWidth / 2, tempMapY + mapImgHeight / 2 --the position in pixels on your map file ( with the upper left corner of this image as origin (0, 0) ) --so now we have the real position in pixels, we draw the the map: dxDrawImageSection ( radarX, radarY, radarWidth, radarHeight, mapX - mapWidth / 2, mapY - mapWidth / 2, mapX + mapWidth / 2, mapY + mapWidth / 2, "map.jpg" ) end addEventHandler ( "onClientRender", root, drawRadar ) Link to comment
Solstice. Posted March 4, 2014 Share Posted March 4, 2014 You need to draw a smaller image section. If your map is 6000 x 6000 then the player position can be an exact pixel. local x, y, z = getElementPosition( getLocalPlayer( ) ) local sx, sy = guiGetScreenSize( ) local radarWidth = 250 local radarHeight = 250 dxDrawImageSection ( sx/2 - radarWidth/2, sy/2 - radarHeight/2, radarWidth, radarHeight, x - mapWidth / 2,y - mapWidth / 2, 250, 250, "map.jpg" ) 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