I am writing a demo with pygame in python, and want to draw a moving object on a static background. But I do not want to update the static background.
At first I want to draw two layers, one for the static background and the other for the moving object. However, I do not find any attribute like layers (just like layers in photoshop). So how can I deal with it.
here is my code:
# -*- coding: utf-8 -*-
import sys
from settings import Settings
import pygame
import math
def run_game():
#
pygame.init()
ai_settings = Settings()
screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
pygame.display.set_caption("Catch Me If You CAN")
radius = 10
#
while True:
#
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
#
screen.fill(ai_settings.bg_color)
pygame.draw.rect(screen, [0, 0, 0], [math.cos(radius)*100+300, math.sin(radius)*50+200, 10, 10], 4)
radius = radius + 0.1
#
pygame.display.flip()
run_game()