Games [XUI2D] Mouse following a path

Discussion in 'Game Development' started by Erel, Nov 1, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed User


    This example shows two things:

    1. How to use a MotorJoint to make a body follow a path of points.
    The difficult part was to make the body turn through the shortest direction.

    A useful FindAngleToTarget sub is included in the example.

    2. How to use the new async drawing features added in BitmapCreator v4.5. These features are very important as they allow us to make drawings directly to X2.MainBC.
    X2.MainBC is the BitmapCreator that all the bodies are drawn to (by default).

    Start with this tutorial:

    It looks like this:
    gs.DrawingTasks.Add(X2.MainBC.AsyncDrawCircle(v.X, v.Y, 5, BrushBackwards, True0))
    BC.AsyncDraw methods do not draw anything. They return a DrawingTask object. This object holds the information that is required to later make the drawing.
    Remember that X2.MainBC is cleared every cycle so you need to draw everything every tick.

    Drawing paths asynchronously requires careful handling. You shouldn't modify the path object while it is being drawn.
    You should use a "copy on write" implementation:
    PathMainBCBackwards = PathMainBCBackwards.Clone
    PathMainBCBackwards.LineTo(v.X, v.Y)
    This way the previous path is kept intact.

    The example is included in the examples pack.
    Beja, Ohanian, Almora and 3 others like this.
  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