![]() |
Help With Lifebar
Hey, whats up everybody? I'm doing a project in programming class and am having trouble with a Lifebar (like in video games). It is very simple, just three pictures of hearts. Every time the label which displays "Computer Wins" is visible, I want a heart to be taken away. How would I go about doing this since I am new?
Thanks |
If these are just Image controls, it's quite easy:
:
imgHeart2.Visible = False |
If you've got more than three hearts though you'd probably want to use a control array at the least...
|
I understand the .visible = false thing, but the thing is I want heart1 to disappear when the losing message appears, then when it appears again, I want the next one disappear and so on.
|
Control arrays break the Form Designer in .NET, unfortunately.
|
what do i do then?
|
Are there only going to be three hearts, or will this number possibly change?
Assuming you only have one picture box (I'll call it imgHearts), you could have an integer variable: Dim NumHeartsLeft as Integer = 3 Then, you could dive into GDI+ and have it draw the hearts on that picturebox: :
Public Sub DrawHearts()This draws as many hearts as are in NumHeartsLeft. You should set HeartPath to the location of the Heart image, and HeartWidth to the actual width of the Heart image. Whenever your player gets hurt, when you show the Label, you should subtract 1 from NumHeartsLeft and call DrawHearts: NumHeartsLeft -= 1 DrawHearts() Some suggestions for the above:
Hope this helped at all. Good luck! |
Thanks a lot. But this is a very simple rock paper scissors program. Every time the computer wins, a label displays saying "Computer Wins" and every time that happens, I want a heart's visibility to be turned off. Once all hearts are off I'm going to have it reset a textbox that adds up the total rounds survived back to zero (I already have the textbox working). I don't know if what you helped me with will help that.
thanks |
If it is very simple, then you could just create three Image controls. I'll call them img1, img2, and img3. If you copy the following sub into your program, and call it whenever the label is shown, it will either make an image invisible, or if all are invisible, it will make all three visible again (for restarting and all):
:
Dim NumHearts As Integer = 3The reason NumHearts is set to 4 instead of 3 in 'Case 0' is because it will have 1 subtracted it from it in the next line, making it 3 and ready to start over again. Good Luck! |
Lifbar *SOLVED*
Thanks a lot for being so helpful. I'm sure this will work.
|
| All times are GMT -5. The time now is 12:57 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC