|
-
May 15th, 2010, 08:41 PM
#1
Thread Starter
Hyperactive Member
Game - Float Points Away
I'm building a card game called 11-UP.
See the game here.
I've gotten to the point where I need to make scores show up when the selected cards have a sum of 11. For example, if the card is worth 200 points, then "200" should become visible for about a second and then "float away".
I know I can do this with a timer and the location property. I was thinking of creating an array of 22 timers, one for each card. When the selected cards have a sum of eleven, I enable the timers for each selected card. The timer makes the "score" for that card appear, then move up a few times, then vanish.
Does anyone have a better way to do it? Maybe with only one timer?
Also, how could I make the "scores" become more transparent as time advances? I'd like to make them not only float away, but also "disolve."
Anyone?
-
May 15th, 2010, 10:24 PM
#2
Frenzied Member
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
-
May 16th, 2010, 04:21 PM
#3
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!)
-
May 16th, 2010, 05:25 PM
#4
Thread Starter
Hyperactive Member
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?
-
May 16th, 2010, 05:44 PM
#5
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"?
-
May 16th, 2010, 06:39 PM
#6
Thread Starter
Hyperactive Member
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?
-
May 16th, 2010, 06:58 PM
#7
Re: Game - Float Points Away
-
May 16th, 2010, 07:16 PM
#8
Thread Starter
Hyperactive Member
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
-
May 17th, 2010, 02:51 AM
#9
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.
-
May 17th, 2010, 01:07 PM
#10
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
Last edited by minitech; May 17th, 2010 at 01:11 PM.
-
May 17th, 2010, 05:37 PM
#11
Thread Starter
Hyperactive Member
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.
-
May 18th, 2010, 12:47 AM
#12
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
-
May 19th, 2010, 02:47 PM
#13
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?
-
May 19th, 2010, 05:57 PM
#14
Re: Game - Float Points Away
I probably do.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|