Games At a loss... I am updating a graphic in an body delegate class

Marc De Loose

Member
Licensed User
Longtime User
I have this in a (body delegate class):

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.
New graphic: bar1.png_12.02x1.82bar1_select.png
over and over. (continuously).

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:

Gunther

Active Member
Licensed User
Longtime User
Hi,

did you checked the rope length code of the Joints Example? There a picture (of the rope) is cutted to the current length of the rope. The one which is at the top fixed to the static block and the donut on the other end.

May be this is the closest what you may try to archive. This pic is loaded once and then cutted and not loaded every tick new from the assets.
 
Last edited:

Marc De Loose

Member
Licensed User
Longtime User
Can you upload the project?
EREL Uploading I can but it will do you no good as it requires another pieces of software you don't have. I could mock something up but it will take too much time. But I think gunther is on to something.
 

Marc De Loose

Member
Licensed User
Longtime User
Hi,

did you checked the rope length code of the Joints Example. There a picture (of the rope) is cutted to the current length of the rope. The one which is at the top fixed to the static block and the donut on the other end.

May be this is the closest what you may try to archive. This pic is loaded once and then cutted and not loaded every tick new from the assets.


I am looking into it now.
 
Last edited:
Top