0:01 / 0:30
Playback speed

Draw order

Follow the card with three pips for one beat. Which card covers the others after the order changes?

#TilesAndWorlds

The order things are painted in. Whatever is drawn last ends up on top.

A 2D game paints like a person with opaque paint: back to front. Layers and z-values are just ways of deciding that order. The pips count the order each card was painted in.

Code

src/demos/draw_order.goose
namespace draw_order_lesson;
import stage;
import std;
import math;

export "draw-order" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
    artwork("draft");
    let offset = (time / 1.4) as i64 % 3;
    for layer in 3 {
        let i = (layer + offset) % 3;
        let x = 38 + i * 20;
        let y = 20 + i * 13;
        rect(x + 3, y + 3, 46, 34, "rgba(14,15,38,.5)");
        rect(x, y, 46, 34, match i { 0 => SUN, 1 => MOSS, _ => SKY });
        artwork(match i { 0 => "coast", 1 => "reef", _ => "valley" }, x + 2, y + 2, 42, 26);
        box(x, y, 46, 34, INK);
        for p in 0..layer + 1 {
            rect(x + 4 + p * 6, y + 29, 3, 3, INK);
        }
    }
}

Stage drawing helpers · All demos on GitHub

Comments

No comments yet.