python - 我如何在 Pygame 中保持旋转正方形?
问题描述
我想知道如何在 pygame 中继续旋转一个简单的正方形。
我用黑色背景和中间绘制的白色方块编写了这个简单的代码。我怎么能一直旋转那个白色方块?
继承人的程序:
import pygame
pygame.init()
window = pygame.display.set_mode((500,500))
pygame.display.set_caption("code man")
# the square
class square:
def __init__(self,x,y,height,width,color):
self.x = x
self.y = y
self.height = height
self.width = width
self.color = color
self.rect = pygame.Rect(x,y,height,width)
def draw(self):
self.rect.topleft = (self.x,self.y)
pygame.draw.rect(window,self.color,self.rect)
white = (255,255,255)
square1 = square(200,200,50,50,white)
# redraw the window
def redraw():
BLACK = (0,0,0)
# fill the window black
window.fill(BLACK)
# draw the square
square1.draw()
# update the screen
pygame.display.update()
# the main loop
runninggame = True
while runninggame:
for event in pygame.event.get():
if event.type == pygame.QUIT:
runninggame = False
# call the redraw
redraw()
解决方案
推荐阅读
- python - Pandas 如何有效地获取不包括 NA 的 JSON/dict 格式的数据帧?
- javascript - 如何删除正则表达式字符中的反斜杠(\)?
- javascript - 如何在插入 sql 查询(Node js)中转售语法错误
- c# - 如何在特定时间在我的 Cocoa 应用程序 (Xamarin.Mac) 上获取上传和下载使用情况
- google-bigquery - 我无法将数据从 BigQuery 迁移到数据洞察
- perl - Mac M1 Homebrew Perl Carton Net::SSLeay 正在以不安全的方式加载 libcrypto
- mysql - SQL:从 2 列数据源创建聚合表
- jsf - Primefaces 10 dataTable p:dataExporter 在迁移后渲染时生成 ArrayIndexOutOfBoundsException
- typescript - 如何具有基于参数的泛型和常量函数返回类型
- c# - Asp.net mvc core在Controller处购买了模板按钮自定义onClick事件