Skip to content

Latest commit

 

History

History
62 lines (44 loc) · 1.37 KB

README.md

File metadata and controls

62 lines (44 loc) · 1.37 KB

Canvas Cake

NPM Package NPM Package NPM Package

CAKES! Everybody loves cakes! Cakes have layers!

-Donkey

This is a simple package to help use layers on the canvas. It simply gives helper classes to add, remove, and move layers around.

Examples

// Basic setup
import Cake from "canvas-cake";

const cake = new Cake(canvas);

const l1 = cake.newLayer();
const l1_ctx = l1.getContext();
l1_ctx.fillRect(0, 0, 50, 50);

const l2 = cake.newLayer(10, 10);
const l2_ctx = l2.getContext();
l2_ctx.fillStyle = "#00aaff";
l2_ctx.fillRect(0, 0, 50, 50);

cake.update();

example1

// Move layer z-index
import Cake from "canvas-cake";

const cake = new Cake(canvas);

const l1 = cake.newLayer();
const l1_ctx = l1.getContext();
l1_ctx.fillRect(0, 0, 50, 50);

const l2 = cake.newLayer(10, 10);
const l2_ctx = l2.getContext();
l2_ctx.fillStyle = "#00aaff";
l2_ctx.fillRect(0, 0, 50, 50);

cake.setLayerZIndex(l2, 0);

cake.update();

example1