简体   繁体   中英

Why is this start_pos invalid?

Why does this code not work?

def grid(vl):
    vl_var = screen.get_width() / vl
    i = 1
    while True:
        if i == vl:
            i = 1
            break
        else:
            pygame.draw.line(screen, (94, 94, 94), vl_var * i, vl_var * i * screen.get_width())
            i += 1

When executing this program, i get the following error

TypeError: invalid start_pos argument

I have no idea why this would be invalid...

To draw a line you need to specify the start and end position. A position is a tuple with a x and y coordinate. pygame.draw.line draws a line from a start and end position specified in the third and fourth parameters. eg:

def grid(vl, hl):
    width, height = screen.get_size()
    vl_var = width // vl
    hl_var = height // hl
    # vertical lines
    for i in range(vl+1):
        pygame.draw.line(screen, (94, 94, 94), (vl_var*i, 0), (vl_var*i, height))
    # horiontal lines
    for i in range(hl+1):
        pygame.draw.line(screen, (94, 94, 94), (0, hl_var*i), (width, hl_var*i))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM