my game currently just embeds the sprites I'm using directly in the code to ignore all of those pesky "this needs to be loaded from a server because accessing local data is
dangerous" issues and I didn't feel like using not-canvas ways to draw the screen
something like
var img=new Image();
img.src= 'data:image/png;base64,[MASSIVE SPEW OF BASE64 DATA LOL]';
and I used the base64 utility to generate that spew of data
something like
$ base64 -w 0 < sprites.png > sprites.txt
(I'm on Windows, but I've got WSL installed -- there's other ways to do it)
then, you copy that text file in, replacing the [MASSIVE SPEW OF BASE64 DATA LOL] bit but leaving the rest
also, you'll need to wait until the image is loaded
my game throws the actual game code in a main() function and has it get called when the data is decoded
img.addEventListener('load', main, false)
like, I cut out the sprites I'm using in GIMP, the whole sheet as base64 would be huge lol
drawing the sprites from a loaded sprite sheet is ezpz, look up ctx.drawImage
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage
in particular,
ctx.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);
image is that image we loaded, sx/sy are where on the sheet to draw from, swidth/sheight are how wide/tall the sprite on the sheet is, dx/dy are where to put it on the canvas, and dwidth/dheight are optional parameters that say how wide/tall to scale the sprite to (so you can scale sprites)
also, I'm not going to lie, I expected this to be a tic-80 compo lol
oh well
doing it on a JS canvas isn't too hard, just has some weird gotchas