[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] coordinates overflow



Hi,

I've discovered that pygame behaves weird when I'm drawing with large
coordinates. For example, the object at position [262144, 300] is
displayed as at [0, 300]. The same is true for negative position
[-262144, 300].

 
See the attached demo for more examples.
Note that 2**18 = 262144.

-- 
Ivo Danihelka
#!/usr/bin/env python
import pygame

SIZE = 800, 600

def checkQuit():
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            return True
        elif event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                return True
    return False

def main():
    pygame.init()
    screen = pygame.display.set_mode(SIZE)

    black = (0, 0, 0, 255)
    white = (255, 255, 255, 255)
    red = (255, 0, 0, 255)

    clock = pygame.time.Clock()
    #NOTE: 2**18 = 262144
    #pos = [-262140, 300]
    pos = [262140, 300]
    while not checkQuit():
        screen.fill(black)

        radius = 100
        pygame.draw.circle(screen, white, pos, radius)
        screen.fill(red, (pos, (40, 40)))

        pygame.display.flip()
        print "pos:", pos
        clock.tick(5)
        pos[0] += 1


#-----------------------------------------------------------------
main()