From fe160efc19cc4bf1f265b41baa7dafdcbe151c92 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Thu, 23 Apr 2020 16:44:16 -0400 Subject: [PATCH] Respect z-order when rendering to the canvas --- macrovision.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/macrovision.js b/macrovision.js index 9263e239..d2de4967 100644 --- a/macrovision.js +++ b/macrovision.js @@ -2278,7 +2278,11 @@ function importScene(data) { function renderToCanvas() { const ctx = document.querySelector("#display").getContext("2d"); - Object.entries(entities).forEach(([id, entity]) => { + Object.entries(entities).sort((ent1, ent2) => { + z1 = document.querySelector("#entity-" + ent1[0]).style.zIndex; + z2 = document.querySelector("#entity-" + ent2[0]).style.zIndex; + return z1 - z2; + }).forEach(([id, entity]) => { element = document.querySelector("#entity-" + id); img = element.querySelector("img");