Jump to content

Text Shadow


MTA.Castiel

Recommended Posts

Hey there! ??

I've recently adjusted a function called - dxDrawTextOnElement which i found on MTA's Wiki, to have a shadow behind each text but here seems to be an issue somewhere.
When i draw certain texts (with certain text lengths) for example: "Shadow Text" and it reaches the left side of the screen, it appears that the text and the shadow clamp together in a single pixel. After moving the text a pixel further off screen the text shadow is seen back in it's correct position again. ?‍♂️

When i draw the text with 1 extra character, for example: "Shadow Texts", when it reaches the left side of the screen, its able to move off screen without any issue while maintaining it's position.

While wring the above post, i been brain storming possible causes:

• Missing an appropriate offset function
• Text Bounding Box
• Screen Bounding Box
I'm not exactly sure on how to approach these, but here's where we are:
- Screenshot: https://imgur.com/a/SwDdUh0

function dxDrawTextOnElement(TheElement,text,height,distance,R,G,B,alpha,size,font,...)
	local x, y, z = getPedBonePosition(TheElement, 5)
	local x2, y2, z2 = getCameraMatrix()
	local distance = distance or 150
	local height = height or 1

	if (isLineOfSightClear(x, y, z+2, x2, y2, z2, ...)) then
		local sx, sy = getScreenFromWorldPosition(x, y, z+height)
		if(sx) and (sy) then
			local distanceBetweenPoints = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2)
			if(distanceBetweenPoints < distance) then

			dxDrawText(text, sx+2, sy+2, sx, sy, tocolor(0, 0, 0, alpha or 255), size or 1, font or "arial", "center", "center")
			dxDrawText(text, sx, sy, sx, sy, tocolor(R or 255, G or 255, B or 255, alpha or 255), size or 1, font or "arial", "center", "center")

			end
		end
	end
end

local testPed = createPed(285, -2307.353, -1611.631, 483.889) --test ped at the top of Mount Chilade

addEventHandler("onClientRender", getRootElement(), function()
	dxDrawTextOnElement(testPed, "Text Shadow", 0.5, 50, 255, 255, 255, 255, 1, "pricedown")
	dxDrawTextOnElement(testPed, "Text Shadows", -0.5, 50, 255, 255, 255, 255, 1, "pricedown")
end)




 

Link to comment

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...