Jump to content

Generating a map of tiles


buryo
 Share

Recommended Posts

Hello,

I'm trying to generate a world map of tiles. But now I'm stuck, I'm getting an error which is impossible to understand. Maybe you will see what's going wrong:

Quote

Error: TypeError: Cannot read property '_pixiId' of undefined

const MAP_WIDTH = 6400; // when I make this value 3200 or 832 it works else not
const MAP_HEIGHT = 6400; // when I make this value 3200 or 832 it works else not

const MAP_WIDTH = 6400; // when I make this value 3200 or 832 it works else not
const MAP_HEIGHT = 6400; // when I make this value 3200 or 832 it works else not
const TILE_WIDTH = 64;
const TILE_HEIGHT = 64;


map = [
    Array.from({ length: MAP_WIDTH }, (_, i) => {
        if (i <= (MAP_WIDTH / 64) || i % (MAP_WIDTH / 64) === 0 || i % (MAP_WIDTH / 64) === (MAP_WIDTH / 64) - 1 || i >= (Math.pow(MAP_WIDTH / 64, 2)) - (MAP_WIDTH / 64)) {
            return 1
        }
        return 0
    })
]


createMap = () => {
    const cols = MAP_WIDTH / TILE_WIDTH;
    const rows = MAP_HEIGHT / TILE_HEIGHT;

    for (let i = 0; i < this.map.length; i++) {
        const layer = this.map[i];
        for (let j = 0; j < rows; j++) {
            for (let k = 0; k < cols; k++) {
                const imageType = layer[j * cols + k];

                let tile = PIXI.Sprite.from(this.images[imageType]);

                tile.x = k * TILE_WIDTH;
                tile.y = j * TILE_HEIGHT;
                tile.width = TILE_WIDTH;
                tile.height = TILE_HEIGHT;

                this.container.addChild(tile);
            }
        }
    }
}

 

Link to comment
Share on other sites

Yeah, demo would be a good thing :)

Anyway, even if we debug it and find the bug:

i recommend to read my tilemap implementation for v5, it was somewhere here: https://github.com/ivanpopelyshev/pixi-starfighter . It has general algorithm that allows not to spawn 100x100 or 1000x1000 tiles for the map and saves a lot of memory and performance. When I approve port of pixi-tilemap from v4 it will be even faster.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...