I have this routine that draws a traffic signal (red, green and yellow circles).
The "Lights" parameter is a 3 character string, consisting of the letters "R", "Y", and "G", in that order.
If the letter is uppercase, the corresponding light is ON, a lowercase letter means the light is OFF:
I define the Canvas1 object in "Sub Globals" and initialize it like this:
The first time I call the subroutine, the lights are drawn as expected. Every time after that, however, all three lights are always black.
Can someone please point out what (dumb) mistake I'm making? Is there something I have to do to "reset" the Canvas before drawing?
Thanks for the help!
Eric
The "Lights" parameter is a 3 character string, consisting of the letters "R", "Y", and "G", in that order.
If the letter is uppercase, the corresponding light is ON, a lowercase letter means the light is OFF:
B4X:
Sub DrawLights(Lights As String)
If Lights.SubString2(0, 1) = "R" Then
Canvas1.DrawCircle(40dip, 200dip, 30dip, Colors.Red, True, 10dip)
Else
Canvas1.DrawCircle(40dip, 200dip, 30dip, Colors.Black, True, 10dip)
End If
If Lights.SubString2(1, 2) = "Y" Then
Canvas1.DrawCircle(40dip, 280dip, 30dip, Colors.Yellow, True, 10dip)
Else
Canvas1.DrawCircle(40dip, 280dip, 30dip, Colors.Black, True, 10dip)
End If
If Lights.SubString2(2, 3) = "G" Then
Canvas1.DrawCircle(40dip, 360dip, 30dip, Colors.Green, True, 10dip)
Else
Canvas1.DrawCircle(40dip, 360dip, 30dip, Colors.Black, True, 10dip)
End If
Activity.Invalidate
End Sub
I define the Canvas1 object in "Sub Globals" and initialize it like this:
B4X:
Sub Activity_Create(FirstTime As Boolean)
.
.
.
Canvas1.Initialize(Activity)
End Sub
The first time I call the subroutine, the lights are drawn as expected. Every time after that, however, all three lights are always black.
Can someone please point out what (dumb) mistake I'm making? Is there something I have to do to "reset" the Canvas before drawing?
Thanks for the help!
Eric