Reputation: 193
It seems like every time I create something in pygame, I have to switch the rows and columns for it to print correctly. For example, if I have:
for col in range(COLS):
board[3][col] = 'tree'
I set up a draw function to draw a sprite whenever the board cell is equal to 3. However, it draws a vertical line of trees instead of horizontal. Since I want to iterate over all the columns in the 3rd row, the correct output should be a horizontal line of trees.
This is just one example out of many, but does anyone have any clue why pygame is doing this?
Upvotes: 1
Views: 416
Reputation: 142641
I think your problem is because in real world we use two systems to describe position.
First uses (x,y)
and you can see in
PyGame
, not only in Python
)Second uses (y,x)
and you can see in
(row, column)
(floor, door)
(row, place)
(latitude, longitude)
You use second system (y,x)
to keep data but Pygame use first system (x,y)
to draw it
so you have to remeber to switch (y,x)
to (x,y)
([row][column]
to [column][row]
)
or you have to keep data as [column][row]
((x,y)
)
Upvotes: 1