I have this in a (body delegate class):
The CreateBar sub is:
It creates a bar with a set length in percent of... (look at the 100 value when I call the CreateBar. That means full length). It is all working fine but.....
I am using an object(tile) as base (or framework) to draw the bar. Object Bar1Base is the background and object Bar1Anker is the part where the bar is drawn. I do this because I can just add and update the json to have other sizes and forms. I do it this way because...
The problem I think I am facing is that it is not efficient as the logs of the debugger show.
I tried going async (x2.MainBC) but I was not able to create other instances of the delegate class as it would update the bar in all the delegates.
My question is simple. Can I do it more efficiently?
One thing to note is that the bar will be update continuously
B4X:
Public Sub Tick (GS As X2GameStep)
If GS.ShouldDraw Then
If Main.gDragMode=False And Main.gDraggingId=0 Then
x2.GraphicCache.RemoveGraphics(Bar1Base.GraphicName)
x2.GraphicCache.PutGraphicBCs(Bar1Base.GraphicName, Array(CreateBar(Bar1Base,Bar1Anker,xui.Color_Red,xui.Color_Green,100)), True, 2)
End If
If Main.Graphs(coupledID,coupledIndex).visible=False Or Main.Graphs(coupledID,coupledIndex).BaseName<>Bar1BaseName Then
Bar1Base.Delete(GS)
Return
End If
Bar1Base.UpdateGraphic(GS,True)
End If
'Log("still here")
End Sub
The CreateBar sub is:
B4X:
rivate Sub CreateBar(BackObject As Object, FrontObject As Object,BackColor As Int, FrontColor As Int,pct As Float) As BitmapCreator
Dim BCBackGround As BitmapCreator
Dim BCForground As BitmapCreator
Dim sizeBCBackGround As B2Vec2 = x2.GetShapeWidthAndHeight(Bar1Base.Body.FirstFixture.Shape)
BCBackGround.Initialize(x2.MetersToBCPixels(sizeBCBackGround.X), x2.MetersToBCPixels(sizeBCBackGround.Y))
Dim sizeBCForground As B2Vec2 = x2.GetShapeWidthAndHeight(Bar1Anker.Body.FirstFixture.Shape)
BCForground.Initialize(x2.MetersToBCPixels(sizeBCForground.X), x2.MetersToBCPixels(sizeBCForground.Y))
Dim gapBackandFront As Float =( BCBackGround.mWidth - BCForground.mWidth)/2
Dim realLength As Float = BCForground.mWidth*(pct/100)
BCBackGround.DrawLine(0,BCBackGround.mHeight/2,BCBackGround.mWidth,BCBackGround.mHeight/2,BackColor,BCBackGround.mHeight)
BCBackGround.DrawLine(gapBackandFront,BCBackGround.mHeight/2,realLength+gapBackandFront,BCBackGround.mHeight/2,FrontColor,BCForground.mHeight)
Return BCBackGround
End Sub
It creates a bar with a set length in percent of... (look at the 100 value when I call the CreateBar. That means full length). It is all working fine but.....
I am using an object(tile) as base (or framework) to draw the bar. Object Bar1Base is the background and object Bar1Anker is the part where the bar is drawn. I do this because I can just add and update the json to have other sizes and forms. I do it this way because...
The problem I think I am facing is that it is not efficient as the logs of the debugger show.
over and over. (continuously).New graphic: bar1.png_12.02x1.82bar1_select.png
I tried going async (x2.MainBC) but I was not able to create other instances of the delegate class as it would update the bar in all the delegates.
My question is simple. Can I do it more efficiently?
One thing to note is that the bar will be update continuously
Last edited: