You must use the async drawing methods if you want to draw on X2.MainBC directly. MainBC is cleared every cycle and then all the async tasks are being drawn.
Your code will completely kill the game performance.
1. You don't need to create a new BitmapCreator for the drawings. This cannot work inside the Ticks event.
2. You should never use 'dip' units in XUI2D.
3. The async methods work with brushes. It will not create the brush for you as it is a mistake to create a new brush every tick.
Correct code:
B4X:
'BrushBackwards is a global variable.
'Created like this: BrushBackwards = X2.MainBC.CreateBrushFromColor(xui.Color_Red)
Public Sub Tick (GS As X2GameStep)
If GS.ShouldDraw Then
GS.DrawingTasks.Add(X2.MainBC.AsyncDrawCircle(100, 100, 50, BrushBackwards, True, 10))
GS.DrawingTasks.Add(X2.MainBC.AsyncDrawLine(0, 0, X2.MainBC.mWidth, X2.MainBC.mHeight, BrushBackwards, 5))
End If
End Sub
BTW, if you want to make static drawings that are not being updated too frequently then you can add another layer (another ImageView) and draw over this layer. This way you will not need to redraw everything each step.
Similar to the "create static background" that is inside many of the example.
For drawings that are related to the world bodies then it is better to use the async approach and draw directly to MainBC.
thanks for your hints and information. I already thought about async drawings but I could it done only after I checked throu your MouseFollowing Example.
Actually it is the same line as it is drawn in DebugMode between Joints but permanently also in release mode.
B4X:
Public Sub Draw(GS As X2GameStep)
'
Dim p1 As B2Vec2 = X2.WorldPointToMainBC(revjoint.AnchorA.X, revjoint.AnchorA.Y)
Dim p2 As B2Vec2 = X2.WorldPointToMainBC(revjoint.AnchorB.X, revjoint.AnchorB.Y)
GS.DrawingTasks.Add(X2.MainBC.AsyncDrawLine(p2.X, p2.Y, p1.X, p1.Y, BrushLineColor, 0.2))
'
End Sub