Я написал небольшую программу для вас, чтобы показать, что я исправляю ранее в комментариях.Надеюсь, поможет.
Вам нужен файл 640x480 test.png в той же папке, что и программа, и вы можете запустить этот код.Это просто простое приложение для рисования.
Холст - это поверхность для рисования, экранный объект - фон.
import pygame as pg
from pygame import Color, Surface
WIDTH = 640
HEIGHT = 480
EMPTY = Color(0,0,0,0)
screen = pg.display.set_mode((WIDTH, HEIGHT))
pg.display.set_caption("Drawing app")
bg = pg.image.load("test.png")
clock = pg.time.Clock()
#I create a transparant canvas
canvas = pg.Surface([640,480], pg.SRCALPHA, 32)
def main():
is_running = True
while is_running:
for event in pg.event.get():
if event.type == pg.QUIT:
is_running = False
elif event.type == pg.KEYDOWN:
if event.key == pg.K_ESCAPE:
is_running = False
elif event.type == pg.MOUSEMOTION:
if pg.mouse.get_pressed()[0]:
#if mouse 1 is pressed, you draw a circle on the location of the cursor
location = (pg.mouse.get_pos())
pg.draw.circle(canvas, (0,0,0), location, 20)
elif event.type == pg.MOUSEBUTTONDOWN:
#clear canvas on mouse button 3 press
if event.button == 3:
canvas.fill(EMPTY)
#I blit the background first!
screen.blit(bg,(0,0))
#afterwards I overwrite it with a transparant canvas with the drawing I want
screen.blit(canvas,(0,0))
pg.display.update()
clock.tick(200)
if __name__ == "__main__":
main()