0

When i finished the part of my code that permanently displays all sprites once,it is still showing only on at a time. I really don't know where the problem is coming from,and thus i was unable to try anything of significance. I'm kind of a noob in pygame so sry if it seems dumb.

import pygame #libs
import socket
from pygame.locals import*
img = pygame.image.load('board.png')#image
circle = pygame.image.load('lowresc.png')#circle
cross = pygame.image.load('lowresx.png')#cross
pygame.init()
pygame.display.set_caption('BoardEngine') #window title

white = (255, 64, 64)
w = 650
h = 650

screen = pygame.display.set_mode((w, h))
screen.fill((white))
running = 1
pygame.event.pump()
key = pygame.key.get_pressed()
#values
amount_circles = 0
amount_crosses = 0
circles = []
crosses = []
a = 0 #amount of total items (may not work in multiplayer)

while running:
    ev = pygame.event.get()
    # proceed events
    for event in ev:
        screen.blit(img,(0,0))
        if event.type == pygame.MOUSEBUTTONUP:
            pos = pygame.mouse.get_pos()
            circles.append(pos)
            a = a + 1
        if a > 0:
            for i in range(len(circles)):
                screen.blit(circle,(circles[len(circles) - 1]))
            for i in range(len(crosses)):
                screen.blit(cross,(crosses[len(crosses) - 1]))
        pygame.display.flip()

        for event in pygame.event.get(): 
             if event.type == pygame.QUIT:
                running = False

1 Answers1

1

Do not implement multiple event loops. Redraw the entire scene in the main application loop.

The main application loop has to:

while running:
    ev = pygame.event.get()
    
    # handle the events 
    for event in ev:
        if event.type == pygame.QUIT:
            running = False
        
        if event.type == pygame.MOUSEBUTTONUP:
            pos = pygame.mouse.get_pos()
            circles.append(pos)

    # draw the background 
    screen.blit(img,(0,0))

    # draw the entire scene
    for i in range(len(circles)):
        screen.blit(circle, circles[i])
    for i in range(len(crosses)):
        screen.blit(cross, crosses[i])

    # update the display
    pygame.display.flip()
Rabbid76
  • 202,892
  • 27
  • 131
  • 174