ftsf / nico

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

24x24 sprite sheet only draws some sprites #102

Closed morganholly closed 1 year ago

morganholly commented 1 year ago

the section at the bottom is two different palettized gradients covering a wide range of colors to test if it had anything to do with the palettization of the spritesheet

image
ftsf commented 1 year ago

Can you please include an example of the code and the spritesheet and what you expect it to look like?

morganholly commented 1 year ago

tiles

import nico

const orgName = "morgan"
const appName = "factory512"

var buttonDown = false

proc gameInit() =
  loadFont(0, "font.png")
  loadSpriteSheet(0, "tiles.png", 24, 24)

proc gameUpdate(dt: float32) =
  buttonDown = btn(pcA)

proc gameDraw() =
  cls()
  setColor(if buttonDown: 7 else: 3)
  for i in 0..<(384 div 8):
    printc("/'\\./'\\./'\\./'\\./'\\./'\\./'\\./'\\./'\\./'\\./'\\./'\\./'\\./'\\./'\\./'\\.", screenWidth div 2, i * 8)
  for j in 0..<100:
    spr(j, (screenWidth div 2) + 24 * (j mod 10) - 120, (screenHeight div 2) + 24 * (j div 10) - 120)

nico.init(orgName, appName)
nico.createWindow(appName, 384, 384, 2, false)
nico.run(gameInit, gameUpdate, gameDraw)

i would expect it to draw each tile in a grid. changing it to 16x16 didn't fix it so i'm confused

morganholly commented 1 year ago

ok if i set the color mode to rgb and reexport it's fixed

image
ftsf commented 1 year ago

The reason it doesn't work is the palette isn't loaded first. You first need to load a palette to specify which colours you're using in your game. Then load your spritesheet, otherwise it will use the default palette.

image

You can save your palette in the GPL (Gimp Palette Format)

morganholly commented 1 year ago

ah that makes sense, thanks