Drawcircle !!!

skipsy

Member
Licensed User
Longtime User
Hello,

I very enjoy trying B4A (looks much easier than Java) but here is a problem
I can't find any solution.
I am testing graphics with a drawcircle function...
This is just a test moving a filled circle, but it does not work.
Does anybody know why :

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim LAYER As Canvas
   Dim TIMER1 As Timer
   Dim x, y As Int
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   LAYER.Initialize( activity)
   If FirstTime Then
      TIMER1.Initialize( "TIMER1", 100 )
      TIMER1.Enabled = True
      x = 0dip
      y = 200dip
   End If
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub TIMER1_tick
   If x < 300 Then
      x = x + 2dip
   End If
   LAYER.DrawCircle( x, y, 20, Colors.red, True, 10dip )
   
End Sub
:sign0163:

Thanks a lot,
WW
 

klaus

Expert
Licensed User
Longtime User
You must add an Activity.Invalidate statement after the DrawCircle statement to force the OS to update the Activity.
B4X:
Sub TIMER1_tick
    If x < 300 Then
        x = x + 2dip
        LAYER.DrawCircle( x, y, 20, Colors.red, True, 1dip )
        Activity.Invalidate
    End If
End Sub
I changed your routine a bit:
- LAYER.DrawCircle( x, y, 20, Colors.red, True, 1dip )
-- 1dip instead of 10dip as you fill it.
-- insides the If statement, no need to draw the circle at the same position, you could even stop the Timer if x>300 with Else.
To make the Activity update faster you could define the surrounding rectangle of the circle and use Invalidate2(rect).
If you would erase the previous circle you need to memorize the current coordinates or better the current surrounding rectangle and draw a transparent rectangle or circle before drawing the new circle.
You could have a look at chapter 14 Graphics in the Beginner's Guide, there are some explained examples in.

Best regards.
 
Upvote 0

skipsy

Member
Licensed User
Longtime User
Oups!
I read something about "Invalidate", and... I forgot it!

Thks for your recommandations too.

Best regards,
W.W.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…