Aego Русский

aego/debug

Shapes last one frame unless Pen gives them a lifetime, and belong to a channel that the Debug Draw panel turns on and off. In the documentation sandbox nothing is drawn; the example logs what it draws. See Debug Draw.

On this page

Example

package demo

import (
    "aego/debug"
    "aego/log"
)

script Patrol {
    @export var Goal Vec2 = Vec2{4, 0}
    @export var Speed float = 2

    var frames int

    func Ready() {
        debug.Pen("ai.goal", -1)
        debug.Cross(Goal, 0.5, Color{1, 0, 1, 1})
        debug.Rect(Rect{-1, -1, 6, 2}, Color{1, 1, 1, 1})
    }

    func Update(dt float) {
        p := node.WorldPosition()
        step := Vec2{Speed * dt, 0}
        if p.X < Goal.X {
            node.SetPosition(node.Position() + step)
        }
        debug.Pen("ai.path", 0)
        debug.Arrow(p, Goal, Color{0, 1, 0, 1})
        debug.Circle(p, 0.5, Color{0, 0.6, 1, 1})
        debug.Text(p, "x " + string(p.X), Color{1, 1, 1, 1})
        frames++
        if frames % 30 == 0 {
            log.Info("drawing at x=" + string(p.X))
        }
        if frames == 90 {
            debug.Clear("ai")
            log.Info("cleared the ai channels")
        }
    }
}

Functions

Arrow(from Vec2, to Vec2, color Color)Draws an arrow from one point to another.
Circle(center Vec2, radius float, color Color)Draws a circle outline with radius r in world units.
Clear(channel string)Removes every primitive whose channel starts with prefix.
Cross(p Vec2, size float, color Color)Draws a cross of the given size in world units.
Line(a Vec2, b Vec2, color Color)Draws a line in world units. It lasts one frame unless Pen sets a lifetime.
Pen(channel string, ttl float)Sets the channel and the lifetime of the next primitives this script draws. A ttl of 0 lasts one frame, a positive ttl that many game seconds, a negative ttl until Clear.
PenUnscaled(channel string, ttl float)Is Pen with a lifetime in real seconds; such primitives fade out while the game is paused.
Point(p Vec2, color Color)Marks a point with a small cross of constant screen size.
Ray(origin Vec2, dir Vec2, color Color)Draws an arrow from origin along dir; the length of dir is the length of the arrow.
Rect(rect Rect, color Color)Draws a rectangle outline.
Text(p Vec2, text string, color Color)Draws a label at a world position; it keeps its screen size at any zoom.

Arrow function

func Arrow(from Vec2, to Vec2, color Color)

Draws an arrow from one point to another.

Example

debug.Arrow(p, p + body.Velocity * 0.2, Color{0, 1, 0, 1})

Circle function

func Circle(center Vec2, radius float, color Color)

Draws a circle outline with radius r in world units.

Example

debug.Circle(node.WorldPosition(), SightRange, Color{0, 0.6, 1, 1})

Clear function

func Clear(channel string)

Removes every primitive whose channel starts with prefix.

Example

debug.Clear("ai")

Cross function

func Cross(p Vec2, size float, color Color)

Draws a cross of the given size in world units.

Example

debug.Cross(goal, 0.5, Color{1, 0, 1, 1})

Line function

func Line(a Vec2, b Vec2, color Color)

Draws a line in world units. It lasts one frame unless Pen sets a lifetime.

Example

debug.Line(node.WorldPosition(), Target.WorldPosition(), Color{1, 0, 0, 1})

Pen function

func Pen(channel string, ttl float)

Sets the channel and the lifetime of the next primitives this script draws. A ttl of 0 lasts one frame, a positive ttl that many game seconds, a negative ttl until Clear.

Example

debug.Pen("ai.path", 2)

PenUnscaled function

func PenUnscaled(channel string, ttl float)

Is Pen with a lifetime in real seconds; such primitives fade out while the game is paused.

Example

debug.PenUnscaled("ui", 1)

Point function

func Point(p Vec2, color Color)

Marks a point with a small cross of constant screen size.

Example

debug.Point(hit.Point, Color{1, 0, 0, 1})

Ray function

func Ray(origin Vec2, dir Vec2, color Color)

Draws an arrow from origin along dir; the length of dir is the length of the arrow.

Example

debug.Ray(node.WorldPosition(), Vec2{0, 2}, Color{1, 1, 0, 1})

Rect function

func Rect(rect Rect, color Color)

Draws a rectangle outline.

Example

debug.Rect(Rect{0, 0, 4, 2}, Color{1, 1, 1, 1})

Text function

func Text(p Vec2, text string, color Color)

Draws a label at a world position; it keeps its screen size at any zoom.

Example

debug.Text(node.WorldPosition(), string(state), Color{1, 1, 1, 1})