sy89
sy89

Reputation: 193

Pygame seems to flip rows and columns?

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

Answers (1)

furas
furas

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

  • computer screen
  • math - point on graph
  • all drawing modules (not only PyGame, not only in Python)

Second uses (y,x) and you can see in

  • matrix in math (row, column)
  • room's numbers (floor, door)
  • tickets in cimena (row, place)
  • geolocation (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

Related Questions