Hey guys, I have been trying to draw a custom HP bar with the drawpoly tool.
So I I have it done and stuff, this is what it looks like:
[URL=http://s1187.photobucket.com/user/Fortune11709/media/polyhp_zpsf140b71c.jpg.html][IMG]http://i1187.photobucket.com/albums/z394/Fortune11709/polyhp_zpsf140b71c.jpg[/IMG][/URL]
The only problem is it doesn't scale properly:
[URL=http://s1187.photobucket.com/user/Fortune11709/media/polyhp2_zps71e6ea53.jpg.html][IMG]http://i1187.photobucket.com/albums/z394/Fortune11709/polyhp2_zps71e6ea53.jpg[/IMG][/URL]
It goes all weird when set to 50 hp. Instead of halving it goes into quarters... Anything below 40-30 just makes it dissapear entirely.
Code:
[CODE]tbl = { {}, {}, {}, {} }
tbl[1]["x"] = 150
tbl[1]["y"] = ScrH()/1.10
tbl[2]["x"] = 440*(health/100)
tbl[2]["y"] = ScrH()/1.10
tbl[3]["x"] = 470*(health/100)
tbl[3]["y"] = ScrH()/1.06
tbl[4]["x"] = 150
tbl[4]["y"] = ScrH()/1.06
surface.SetDrawColor(Color(255,25,25,255))
draw.NoTexture()
surface.DrawPoly( tbl )
[/CODE]
No idea what is wrong, that formula has worked on all the other health bars I have made.
[QUOTE=Fortune11709;43479057]Hey guys, I have been trying to draw a custom HP bar with the drawpoly tool.
So I I have it done and stuff, this is what it looks like:
[URL=http://s1187.photobucket.com/user/Fortune11709/media/polyhp_zpsf140b71c.jpg.html][IMG]http://i1187.photobucket.com/albums/z394/Fortune11709/polyhp_zpsf140b71c.jpg[/IMG][/URL]
The only problem is it doesn't scale properly:
[URL=http://s1187.photobucket.com/user/Fortune11709/media/polyhp2_zps71e6ea53.jpg.html][IMG]http://i1187.photobucket.com/albums/z394/Fortune11709/polyhp2_zps71e6ea53.jpg[/IMG][/URL]
It goes all weird when set to 50 hp. Instead of halving it goes into quarters... Anything below 40-30 just makes it dissapear entirely.
Code:
[CODE]tbl = { {}, {}, {}, {} }
tbl[1]["x"] = 150
tbl[1]["y"] = ScrH()/1.10
tbl[2]["x"] = 440*(health/100)
tbl[2]["y"] = ScrH()/1.10
tbl[3]["x"] = 470*(health/100)
tbl[3]["y"] = ScrH()/1.06
tbl[4]["x"] = 150
tbl[4]["y"] = ScrH()/1.06
surface.SetDrawColor(Color(255,25,25,255))
draw.NoTexture()
surface.DrawPoly( tbl )
[/CODE]
No idea what is wrong, that formula has worked on all the other health bars I have made.[/QUOTE]
You aren't accounting for the starting x position of your health bar in points 2 and 3. That formula assumes it starts at 0, when points 1 and 4 say it starts at 150.
[QUOTE=Jcw87;43483768]You aren't accounting for the starting x position of your health bar in points 2 and 3. That formula assumes it starts at 0, when points 1 and 4 say it starts at 150.[/QUOTE]
Ah, okay. So how should I go about fixing this issue? Should I change points 1 and 4 or 2 and 3. To something like this?:
[CODE]tbl = { {}, {}, {}, {} }
tbl[1]["x"] = 150
tbl[1]["y"] = ScrH()/1.10
-- I don't really know, can't test right now.
tbl[2]["x"] = 440*(health/100) + 150
tbl[2]["y"] = ScrH()/1.10
-- I don't really know, can't test right now.
tbl[3]["x"] = 470*(health/100) + 150
tbl[3]["y"] = ScrH()/1.06
tbl[4]["x"] = 150
tbl[4]["y"] = ScrH()/1.06[/CODE]
[QUOTE=Fortune11709;43483812]Ah, okay. So how should I go about fixing this issue? Should I change points 1 and 4 or 2 and 3.
[/QUOTE]
Well, that depends entirely on whether or not you want 150 pixels of space between your health bar and the left side of the screen (I assume you do.)
[QUOTE=Fortune11709;43483812]
To something like this?:
[CODE]tbl = { {}, {}, {}, {} }
tbl[1]["x"] = 150
tbl[1]["y"] = ScrH()/1.10
-- I don't really know, can't test right now.
tbl[2]["x"] = 440*(health/100) + 150
tbl[2]["y"] = ScrH()/1.10
-- I don't really know, can't test right now.
tbl[3]["x"] = 470*(health/100) + 150
tbl[3]["y"] = ScrH()/1.06
tbl[4]["x"] = 150
tbl[4]["y"] = ScrH()/1.06[/CODE][/QUOTE]
If my assumption is correct, that should do the trick. But why are you asking me for confirmation, instead of just trying it out?
[QUOTE=Jcw87;43484019]Well, that depends entirely on whether or not you want 150 pixels of space between your health bar and the left side of the screen (I assume you do.)
If my assumption is correct, that should do the trick. But why are you asking me for confirmation, instead of just trying it out?[/QUOTE]
It was kind of in the code, but I can't test it at the moment.
Sorry, you need to Log In to post a reply to this thread.