@litecanvas/utils
Version:
Utilities to help build litecanvas games
52 lines (47 loc) • 1.55 kB
JavaScript
(() => {
// src/_global.js
globalThis.utils = globalThis.utils || {};
globalThis.utils.global = () => {
for (const key in globalThis.utils) {
if ("global" === key) continue;
globalThis[key] = globalThis.utils[key];
}
};
// src/image/tint.js
var tint_default = (img, color, opacity = 1, engine = globalThis) => {
return engine.paint(img.width, img.height, (ctx) => {
engine.push();
engine.alpha(opacity);
engine.rectfill(0, 0, img.width, img.height, color);
ctx.globalCompositeOperation = "destination-atop";
engine.alpha(1);
engine.image(0, 0, img);
engine.pop();
});
};
// src/image/scale.js
var scale_default = (img, factor, pixelart = true, engine = globalThis) => {
return engine.paint(img.width * factor, img.height * factor, (ctx) => {
engine.push();
ctx.imageSmoothingEnabled = !pixelart;
engine.scale(factor);
engine.image(0, 0, img);
engine.pop();
});
};
// src/image/flip.js
var flip_default = (img, horizontal = true, vertically = false, engine = globalThis) => {
return engine.paint(img.width, img.height, (ctx) => {
engine.push();
engine.scale(horizontal ? -1 : 1, vertically ? -1 : 1);
engine.image(horizontal ? -img.width : 0, vertically ? -img.height : 0, img);
engine.pop();
});
};
// src/image/_web.js
globalThis.utils = Object.assign(globalThis.utils || {}, {
tint: tint_default,
scaleImage: scale_default,
flipImage: flip_default
});
})();