Pixel art not working

Question:
I am in the first stage on my game, and I am just testing the pixel art, it is supposed to print in the colors of the pixels in the debug console, but it is showing as undefined and throwing a TypeError.
Repl link: https://elemental.element1010.repl.co, https://replit.com/@element1010/Elemental

let debug = true

let pixels = {
  "0": [0, 0, 0] // black
}

let PixelArt = {
  "player": [ // The player will be a cube until we get better graphics
    "00000",
    "00000",
    "00000",
    "00000",
    "00000"
  ]
}

function buildPixelart(texture) {
  for(let i = 0; i < texture.length; i++) {
    for(let j = 0; j < texture[i].length; j++) {
      let color = pixels[texture[i][j]];
      if(debug) {
        console.log(color[0]);
      }
    }
  }
}

Change the last line of your code to:

buildPixelart(PixelArt["player"])

You were trying to perform bulidPixelArt with the text ‘player’ rather than what you wanted to index.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.