pygame 基础学习1:
screen = pygame.display.set_mode((600, 400)) 作主屏幕
pygame.Surface 作子屏幕, 并在该子屏幕上画圆
代码:
import pygame
class sub_screen():
def __init__(self, screen,x,y,w,h,color): #sub_screen(w,h,color) in screen toleft at x,y
self.w=w
self.h=h
self.scr=pygame.Surface((self.w,self.h))
self.scr.fill(color)
self.rect=self.scr.get_rect(topleft=(x,y))
self.screen=screen
def draw_circle(self,x,y,color,r):
pygame.draw.circle(self.scr,color,(x,y),r)
def show(self):
self.screen.blit(self.scr,self.rect)
pygame.init()
screen = pygame.display.set_mode((600, 400))
r=30
s1=sub_screen(screen,0,0,100,100,(0,250,0))
s1.draw_circle(50,50,(250,250,250),r)
s2=sub_screen(screen,200,200,100,100,(0,0,150))
s2.draw_circle(50,50,(250,0,250),r)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
s1.show()
s2.show()
pygame.display.update()