btco / qx82

Tiny Javascript engine for retro games
MIT License
425 stars 20 forks source link

Define your own characters #2

Closed photonstorm closed 1 year ago

photonstorm commented 1 year ago

This is great fun :) I had a blast creating a little starfield effect and a small game.

I think it would be a really nice idea to allow users to create custom characters. This is very in keeping with retro systems, where you could often redefine the pixels of character sets.

Rather than go to that extreme, I think it'd be great to be able to pass an array of 0/1 values to a function that created a new character that could be used with qx.spr or qx.printChar. Or, I guess when you load the chr.png, you render it to a canvas - then a function could overwrite any character in that canvas with your own based on the pixel data you pass.

I guess you'd have to run regenColors() each time they did this, so it would need some additional code to handle the tempCanvas and this.chrImages_ that textrenderer creates, or it would just keep creating them for every custom character. Even so, it would allow for custom sprites without the need to edit the png, which I think makes sharing games much more accessible :)

Anyway, just a suggestion!

btco commented 1 year ago

Ah, yes, that would be pretty cool! I'll think about adding something like that.

btco commented 1 year ago

Added!

You can now load a custom font with qxa.loadFont(), then use it with qx.setFont(). Also added an example showing how to use it, see example-fonts.html.

Thanks for the feature request!