ftsf / nico

a Game Framework in Nim inspired by Pico-8.
MIT License
630 stars 36 forks source link

Load full screen image? #65

Closed madasebrof closed 3 years ago

madasebrof commented 3 years ago

Sorry--this is more of a question, not an issue!

Is there a way to load a large (e.g. full screen or 128 x 128) indexed PNG image as a background? I tried creating a single sprite, but it didn't seem to work.

Thanks!

ftsf commented 3 years ago

@madasebrof you can load a spritesheet and specify the tilesize, if your tile size is the same as the spritesheet size it'll be one full sprite.

eg.

# assuming background.png is a 128x128 png and you want to draw the whole thing to the screen.

# init
loadSpritesheet(1, "background.png", 128, 128)

# draw
setSpritesheet(1)
spr(0, 0, 0)
madasebrof commented 3 years ago

I tried something similar previously.

I just did the above & I get:

Error: unhandled exception: key not found: (r: '\x1D', g: '+', b: 'S', a: '\xFF') [KeyError]
Error: execution of an external program failed: '/Users/adam/dev/nim/console-nim/exampleApp '

The error is just coming from the loadSpritesheet(1, "background.png", 128, 128) line. Is there an expectation for PNG format? E.g. w Alpha, or something? Or is there a particular png editor you use that will generate "correct" output for nico?

I even tried to re-save the png just to double-check the format...

Thanks!!!!

madasebrof commented 3 years ago

Yeah, I just created a brand new image in an online pixel editor, saves as 128x128 png, and I get the same error.

madasebrof commented 3 years ago

Okay, sorry--last post! I did a check by loading an image from the nico examples folder. It works! So there is something specific about the PNG files you created for the examples that nico likes!

Do let me know if there is a specific program you used to create the PNGs for nico, because that seems to be the issue.

madasebrof commented 3 years ago

Okay, I recompiled nico, did a nimble install from source, all works great! No idea why, but there you have it.