bandi94 Posted October 7, 2011 Share Posted October 7, 2011 (edited) i make a new health and speed bar now if i set n for 0.5 the bar is ok ( |_____ ...... | the bar ____ is the progress bar and ... is only for space) if i set it to a smaler number ex. 0.2 the bar move to the center ( |..... __ ..... |) how can i make it to don't move the bar to the center to stay at the begin thx local main = guiCreateStaticImage( 0.81, 0.056, 0.165, 0.11,"fo.png", true ) local zold=guiCreateStaticImage( 0.16 ,0.38, .1 , 0.033 ,"hpg.png", true,main) local n =0.5 guiSetSize(zold,n,0.23,true) Edited October 7, 2011 by Guest Link to comment
Aibo Posted October 7, 2011 Share Posted October 7, 2011 why are you changing position then? Link to comment
bandi94 Posted October 7, 2011 Author Share Posted October 7, 2011 oh i added that line by mistake i tryed to solve the problem whit changing the Position but i need some equation i figured up that if the n=0.05 then the after the equation i need to get 0.19 and whit same equation whit n=1 i need to get 0.032 now i a working to find out the equation or is a easier way ? Link to comment
Aibo Posted October 7, 2011 Share Posted October 7, 2011 easier way would be using absolute positioning. and i dont really get your relative values. are you sure you got them right? relative means relative to the parent. and what the purpose of 0.05 to 0.19 and 1 to 0.032? Link to comment
bandi94 Posted October 7, 2011 Author Share Posted October 7, 2011 i hope you understund me better whit the pictures pic 1 n=0.5 the bar is fine local main = guiCreateStaticImage( 0.81, 0.056, 0.165, 0.11,"fo.png", true ) local zold=guiCreateStaticImage( 0.11 ,0.38, .1 , 0.033 ,"hpg.png", true,main) local n =0.5 guiSetSize(zold,n,0.23,true) http://imageshack.us/photo/my-images/94/problem1n.png/ local main = guiCreateStaticImage( 0.81, 0.056, 0.165, 0.11,"fo.png", true ) local zold=guiCreateStaticImage( 0.11 ,0.38, .1 , 0.033 ,"hpg.png", true,main) local n =0.2 guiSetSize(zold,n,0.23,true) pic 2 n=0.2 after i lost 30 hp now my bar is smaller in width but he moved to left i don't wanna to move the bar to left only to get smaler or bigger in width http://imageshack.us/photo/my-images/571/problem2e.png/ thx Link to comment
Aibo Posted October 7, 2011 Share Posted October 7, 2011 to get width you just need health% / 100 * bar full width. and it shouldn't change position. either you're not showing the whole code (you lost 30 hp but you set bar size with some "n" variable?), or no idea. Link to comment
bandi94 Posted October 7, 2011 Author Share Posted October 7, 2011 whit that n i tryed to move back the healtbar but i deletet that line this is the full code (the healt bar part. I have the timer and the FPS ping part but that is not a problem .. ) now if i have health set to 1-10 the bar is ok if i set it to a bigger number 40-50 again start to moving now to right .... -------------------------elet sebeseg------------- local main = guiCreateStaticImage( 0.81, 0.056, 0.165, 0.11,"fo.png", true ) local zold=guiCreateStaticImage( 0.190 ,0.372, 1 , 0.233 ,"hpg.png", true,main) local health=50 local n =health / 100 *1 guiSetSize(zold,n,0.23,true) the 2 image what i use on guiCreateStaticImage pic 1 http://imageshack.us/photo/my-images/338/16211163.png/ pic 2 http://imageshack.us/photo/my-images/811/hpg.png/ Link to comment
Castillo Posted October 7, 2011 Share Posted October 7, 2011 Why are you not using DX drawing? they're perfect for this kind of script. Link to comment
bandi94 Posted October 7, 2011 Author Share Posted October 7, 2011 whit gui its litel easier positioning and tryed now whit Dx drawing and it same like if i create an image dxDrawImage(screenWidth/2 ,0 , n, 40, 'hpg.png') and if n is 100 and after i change n to 200 it move's a litel to right/left so i need to adjust the cordinates and here is the problem to change the width but only make the bar shorter to don't move it left or right Link to comment
Castillo Posted October 7, 2011 Share Posted October 7, 2011 I'm currently using DX drawing to draw several "loading bars" and works perfectly. Link to comment
bandi94 Posted October 7, 2011 Author Share Posted October 7, 2011 and you just change the Dx drawing width or you are using some adjust for x,y, width,height bk if i add only x=.. y=.. and i change the width the image it will move and then i need to adjust the x back and there i get stuk how to calculate how much i need to adjust the x to stay on place ( bk i need to calculate from health 0-100 and speed 0-250 ) to don't move .... Link to comment
Castillo Posted October 7, 2011 Share Posted October 7, 2011 If I'm right, I change the width acording to my value. Link to comment
jkub Posted December 15, 2011 Share Posted December 15, 2011 to get width you just need health% / 100 * bar full width. and it shouldn't change position.either you're not showing the whole code (you lost 30 hp but you set bar size with some "n" variable?), or no idea. I know this is an old thread but I am not the best with the whole math part when it comes to LUA. I used your fomula for the health bar for myself and it works great. I was about to make a new post on the forum asking how to do it but I'm glad I found the formula. Thanks. 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