HUD rotate texture to get a better hp bar

[LUA]
function draw.GradientRectRot(x,y,w,h,color,r)
surface.SetDrawColor(color)
surface.SetTexture( gradient )
surface.DrawTexturedRectRotated(x-(w/2), y+(h/2), w, h, r );
–surface.DrawTexturedRect( x, y, w, h )
– Sample
–surface.DrawTexturedRect( 0, ScrH()-50, 300, 50 )
end

hook.Add( “HUDPaint”, “PolygonTest”, function()
draw.NoTexture()
draw.GradientRectRot(ScrW()/2, ScrH()/2, 90, 100,Color(200,200,0,255),90)

end )[/LUA]
When Width is 200:

When Width is 90:

My problem is it not rotate the texture. It rotates everything. I would like to make a bar with gradient from bottom to top. Also width is coming from left to right and not right to left.
Sorry for my bad english. You can see when I change size it changes the position in x and y. Anybody can help me?

I’m not quite sure what you’re asking, but when you rotate it by 90 degrees. The ‘width’ and ‘height’ basically swap(not exactly, but their axis sort of do).

Width normally extends this direction ----> but when rotated by 90 degrees it will be extending UP (^^^)

Depending on your rotation, you should be able to just swap the W and H inputs, and it would act how you’d like it. If you want it to extend downwards, you would either need to rotate it by 270 degrees, which would rotate the gradient more. Or calculate how much you need to extend it by, add it to the Y position, and minus that from the height.



hook.Add( "HUDPaint", "PolygonTest", function()
	local width, height = 90, 100;
	draw.NoTexture()
	draw.GradientRectRot(ScrW()/2, ScrH()/2, height,width,Color(200,200,0,255),90) --Swap the width/height.
	
end )


You could also save the trouble and just make a new material with the gradient you want.

One more question. If I increase Height when I rotated for me it will increase to left side not to right :slight_smile: But that material position I want. I still stuck :smiley: I know that width and heigth swap.

Just imagine the size without being rotated, like 20x50, and then you rotate it, you rotate a rect, remember that, you are not transforming a rect

so I need to get the texture and rotate it like in photoshop then save it.

No, you have to understand how rotating works
First you have to scale it and then the function rotates it