To exercise, I tried to generate a basic tilemap in 1 array, but my tiles don't line up along the x-axis as they are supposed to. I can somehow accept why it doesn't work but I can't solve the problem.
Here's the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | for int screen = 0; screen < 4; ++screen { for int y = 0; y < tilesY; ++y { for int x = 0; x < tilesX; ++x { int value = 0; if y == 0 { value = 1 } grid[screen * tilesY * tilesX + y * tilesX + x] = value; } } } |
On the first screen the y is correctly drawn at the bottom row. But when I change screens in X, the row is drawn on a different y coordinate each screen. ( 1 row lower every screen, until it wraps to the top row, again )
When I change screens in Y the row is drawn on the same coordinate.
I know this is a basic question of the layout of an array but I can't visualize how I should correctly do this in 1 array. Or should I make an array of width*height tiles for each screen?
I'm sorry if this is too simple a question. :blush: