Games how to draw a line?

Discussion in 'Game Development' started by Gunther, Oct 31, 2018.

  1. Gunther

    Gunther Active Member Licensed User

    Adding this in the game tick doesn't do the job:

    Code:
    X2.MainBC.DrawLine(revjoint.BodyA.Position.X,revjoint.BodyA.Position.Y, revjoint.BodyB.Position.X,revjoint.BodyB.Position.Y, 12)
     
    Last edited: Oct 31, 2018
  2. Erel

    Erel Administrator Staff Member Licensed User

    I'll soon release a major update to BitmapCreator that will offer more and better options. Stay tuned.

    Testing it as we speak...

    test.gif
     
    DonManfred, inakigarm, klaus and 4 others like this.
  3. ilan

    ilan Expert Licensed User

    Bodyx.Followpath function?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    No. BitmapCreator is responsible for the drawings. The update includes all kinds of drawing methods that can be used with XUI2D and without it.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Will be released tomorrow.

    test.gif
     
  6. Gunther

    Gunther Active Member Licensed User

    Unfortunately I am not getting a line drawn with BC 4.5

    I put this in the Tick of the Game:

    Code:
    Dim bc As BitmapCreator
            bc.Initialize(X2.MainBC.mWidth , X2.MainBC.mHeight)
            bc.DrawCircle(
    100dip100dip50dip, xui.Color_Red, True10dip)
            bc.DrawLine(
    00, bc.mWidth, bc.mHeight, 0xff0000ff5dip)
            X2.MainBC.DrawBitmap(bc.Bitmap,X2.MainBC.TargetRect,
    True)
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    See the mouse example and read the explanation: [XUI2D] Mouse following a path

    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.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    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:
    Code:
    '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(
    10010050, BrushBackwards, True10))
           GS.DrawingTasks.Add(X2.MainBC.AsyncDrawLine(
    00, X2.MainBC.mWidth, X2.MainBC.mHeight, BrushBackwards, 5))
       
    End If
    End Sub
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    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.
     
  10. Gunther

    Gunther Active Member Licensed User

    Dear Erel,

    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.

    Code:
    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
     
    Last edited: Nov 1, 2018
    Erel likes this.
  11. Erel

    Erel Administrator Staff Member Licensed User

    (Don't confuse 'debug drawing' with debug / release compilation. These are two different and unrelated features)
     
  12. Gunther

    Gunther Active Member Licensed User

    Sure!!

    It was only to tell what is the aim to archive with this line on the MainBC.

    Thanks
     
    Last edited: Nov 2, 2018
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice