O
O
OccamaRazor2017-02-17 23:55:09
Python
OccamaRazor, 2017-02-17 23:55:09

How to display several figures on the display, get their coordinates and write the coordinates to an array, which can then be manipulated?

I only display 1 image. To display several, respectively, you need a cycle. But where to insert it so that the data can be controlled and the pictures are displayed on the new coordinates every time the coordinates change?

class figure(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load(os.path.join(IMG,"figure.png")).convert()
        self.image.set_colorkey(BLACK) # made bg transparent
        self.rect = self.image.get_rect()
        self.rect.x = 35
        self.rect.y = 35
        self.image = pygame.transform.scale(self.image, (70, 70))

all_sprites = pygame.sprite.Group()
figure= figure()
all_sprites.add(figure)
all_sprites.draw(screen)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tsarevfs, 2017-02-18
@tsarevfs

You need to have not an array of coordinates, but an array of shapes. On each iteration (on each frame), loop through all the shapes and move them around.

for figure in all_sprites.sprites():
   figure.rect.move_ip(1, 0) #то же что и figure.rect.x += 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question