A little help with health meters.
Blitz3D Forums/Blitz3D Beginners Area/A little help with health meters.
| ||
I've been using the follwing code which I believe I found here for a health bar. The problem I'm having is that the bar goes from right(full life) to left(no life). I've been trying to get it work the other way, left to right, but all my attempts have failed. Can anyone help me solve this badboy? here's the code- Full=LoadImage("Life_Bar.png") ResizeImage Full,247,13 Empty=LoadImage("Life_Bar_2.png") ResizeImage Empty,247,13 SetBuffer BackBuffer() dn=1 Repeat Cls Text 1,1,"Health = "+n n=n+dn If n=100 Then dn=0-1 If n=0 Then dn=1 DoPowerBar(100,100,n,11,86,empty,full) Flip Delay 5 Until KeyDown(1) Function DoPowerBar(Xpos,Ypos,Percent_Filled,StartX,EndX,emptyimage,fullimage) ;X + Y Pos - where on screen you want the bar ;Percent Filled (0-100%) ;StartX - Where on the image you want 0% to be ;EndX - Where on the image you want the 100% to be ;Empty + Full image - the two images DrawImage emptyimage,xpos,ypos from=ImageBuffer(fullimage) high=ImageHeight(fullimage) If percent_filled<>0 Then wide=(((endx-startx)*Percent_Filled)/100)+StartX If percent_Filled=0 Then wide=startX CopyRect 0,0,wide,high,XPos,YPos,from,BackBuffer() End Function |
| ||
Couldn't you just change the start (0) to the end (endx)? Your copyrect would look something like: CopyRect (endx-wide),0,wide,high,XPos,YPos,from,BackBuffer() I just looked over it quickly and didn't test anything so... |
| ||
the way i did my health bars is to use drawimagerect. it take an image and draw a rectangular section. very quick and very easy to useDrawImageRect image,x,y,rect_start_x,rect_start_y,rect_width,rect_height,[frame] i did DrawImageRect img_hbar,hx,hy,0,0,imagewidth(img_hbar)*(remain_health/full_health),imageheight(img_hbar) did the trick for me. divides the remaining health by what the full health number should be, and muliples the image rectangle by it, so it reduces more as the health variable goes down. hope that helps some more! And also, isn't copyrect a wee bit slow? |