why isnt the kaboom.js picking up the map array?

91 Views Asked by At

the code

    kaboom();

    loadSprite("player", "/bean.png");
    loadSprite("grass", "/grass.png");

    const m1ap = [
        '----------------',
        '----------------',
        '----------------',
        '----------------',
        '----------------',
        '----------------'
    ];

    const level_config = {
        tileWidth:64,
        tileHeight:64,


        "-": () => [
            sprite("grass"),
            "block",
            area(),
            body(),
        
        ]
    };

    var level = addLevel(m1ap, level_config);

the error showing is: typeError: Cannot read properties of undefined (reading '-')

i tried everything but nothing works even tried using width and height instead of tileWidth etc

im using kaboom.js library

1

There are 1 best solutions below

0
John Pavek On BEST ANSWER

Wrap the tile methods in a tiles object.

It looks like in version 3000, kaboom now looks in tiles for parsing the map. https://github.com/replit/kaboom/blob/master/CHANGELOG.md#v300000

kaboom();

loadSprite("player", "/bean.png");
loadSprite("grass", "/grass.png");

const m1ap = [
    '----------------',
    '----------------',
    '----------------',
    '----------------',
    '----------------',
    '----------------'
];

const level_config = {
    tileWidth:64,
    tileHeight:64,

    tiles: {
        "-": () => [
            sprite("grass"),
            "block",
            area(),
            body(),        
        ]
    }
};

var level = addLevel(m1ap, level_config);