Re: Game - Float Points Away
I couldn't find anything on opacity in any controls besides a form. You might want to make a class that inherits from system.windows.form.label and then create a function which forces it to draw more and more opaque.
Justin
Re: Game - Float Points Away
No need, just slowly fade it out to the form's background color. Use this function:
Code:
Private Function CombineColors(ByVal color1 As Color,ByVal color2 As Color,ByVal weighting As Single) As Color 'Weighting is from 0.0 (all color1) to 1.0 (all color2).
Dim c1 As Single = 1.0! - weighting
Dim c2 As Single = weighting
Dim color1ret As Color = Color.FromArgb(255,CInt(Math.Round(color1.R * c1)),CInt(Math.Round(color1.G * c1)),CInt(Math.Round(color1.B * c1)))
Dim color2ret As Color = Color.FromArgb(255,CInt(Math.Round(color2.R * c1)),CInt(Math.Round(color2.G * c1)),CInt(Math.Round(color2.B * c1)))
Dim colorret As Color = Color.FromArgb(255,color1ret.R+color2ret.R,color1ret.G+color2ret.G,color1ret.B+color2ret.B)
Return colorret
End Function
Like so (this is in a timer):
Code:
Me.Label1.ForeColor = CombineColors(Me.BackColor,Me.Label1.ForeColor,0.9!)
Re: Game - Float Points Away
mini, I see what you're trying to do but this code doesn't seem to do it. Did you test it first?
Re: Game - Float Points Away
I did test the function, not the color code, but I thought that would be simple enough. What do you mean, "it doesn't work"?
Re: Game - Float Points Away
I mean I don't get any color change. Do I need to edit something in my code other than enabling the timer?
Re: Game - Float Points Away
Re: Game - Float Points Away
Code:
Option Explicit On
Option Strict On
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
End Sub
Private Function CombineColors(ByVal color1 As Color, ByVal color2 As Color, ByVal weighting As Single) As Color 'Weighting is from 0.0 (all color1) to 1.0 (all color2).
Dim c1 As Single = 1.0! - weighting
Dim c2 As Single = weighting
Dim color1ret As Color = Color.FromArgb(255, CInt(Math.Round(color1.R * c1)), CInt(Math.Round(color1.G * c1)), CInt(Math.Round(color1.B * c1)))
Dim color2ret As Color = Color.FromArgb(255, CInt(Math.Round(color2.R * c1)), CInt(Math.Round(color2.G * c1)), CInt(Math.Round(color2.B * c1)))
Dim colorret As Color = Color.FromArgb(255, color1ret.R + color2ret.R, color1ret.G + color2ret.G, color1ret.B + color2ret.B)
Return colorret
End Function
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Me.Label1.ForeColor = CombineColors(Me.BackColor, Me.Label1.ForeColor, 0.9!)
End Sub
End Class
Re: Game - Float Points Away
You're not seeing any change because you aren't making any change. You're supposed to change the 'weighting' so that the resulting Color value changes. This is an example of why I tend to avoid posting code.
Re: Game - Float Points Away
Uh... what? The code does change the weighting, that's what the 0.9! part is for.
Sorry about that, I guess I did make some changes before using it in my program...
Code:
Private Function CombineColors(ByVal color1 As Color,ByVal color2 As Color,ByVal weighting As Single) As Color 'Weighting is from 0.0 (all color1) to 1.0 (all color2).
Dim c1 As Single = 1.0! - weighting
Dim c2 As Single = weighting
Dim color1ret As Color = Color.FromArgb(255,CInt(Math.Round(color1.R * c1)),CInt(Math.Round(color1.G * c1)),CInt(Math.Round(color1.B * c1)))
Dim color2ret As Color = Color.FromArgb(255,CInt(Math.Round(color2.R * c2)),CInt(Math.Round(color2.G * c2)),CInt(Math.Round(color2.B * c2)))
Dim colorret As Color = Color.FromArgb(255,color1ret.R+color2ret.R,color1ret.G+color2ret.G,color1ret.B+color2ret.B)
Return colorret
End Function
Re: Game - Float Points Away
Any suggestions how to trigger a stop for the fading? I tried
Code:
If Label1.ForeColor = Me.BackColor Then
Timer1.Enabled = False
Label1.ForeColor = Color.Black
End If
but the colors never are equal. Rounding error.
I still don't quite understand how .FromArgb works either. Maybe if that made more sense to me, I could do the math.
Re: Game - Float Points Away
Sorry, I didn't read the code carefully enough.
I put this code in my Tick event handler and it stopped the Timer when the Label stopped changing colour:
Code:
If colorret = color2 Then
Me.Timer1.Stop()
End If
Re: Game - Float Points Away
colorret isn't a variable in that block, and neither is color2... Do you mean put it in the CombineColors function?
Re: Game - Float Points Away