Where did I go wrong in making a loop of this 2D array?
So I spent a while trying to loop through my 2D array and draw my texture for each place in the array, eventually making a 15x15 grid, and I got to it in the end eventually with help but don't understand what I did wrong in my original code?
12 Replies
This is the correct version ^
and this is what i did beforehand (it only displayed the first row correctly and for the second row it was just 1 box texture)
your code doesn't access
i
or j
or the items in gameBoardArray
. the code you say is working is also not accessing j
or the itemsim sorry i dont quite understand, my code isnt meant to access the items if that clears anything up, its just a placeholder, a 15x15 array which i can iterate through to display the gameboard
in other words, theres no actual content in the array if that helps?
well in the first sample you are changing x
How did you get the
tilePosition
without using j
?for each j (tile in each row) it adds 81 to the x value (81 is the width of 1 tile) so i jkust incremented it like that
Why do then, when you multiple
i
by 61 each time? You do the same thing on two different ways.
Why 71 and 61 instead of 70 and 60? Why the weirdness with tilePosition being set both inside and outside the inner loop, with different X coordinates each time? There's loads of unexplained stuff, which makes it hard to spot the bit that's wrong71 and 61 is to leave a little gap between the tiles, its just for aesthetic preference but ill show the difference
this is it being 61 and 71
this is 60 and 70
the outside x is to reset for every row so that they start at the same x position so they can display under each other and the y accesses the i value so if it was the 2nd row itd multiply 61 (the height of a tile) by 2 to put it in the 2nd row if that makes any more sense
the + 100 is just to set a gap from the top of the screen
i hope that cleared some stuff up, if not just lmk and ill try my best
also sorry, forgot to mention but the beforehand screenshot, i had the width and height as 80 but swapped it later to 70 and 60