python - Modify ellipse coordinates in pygame
问题描述
I have been trying to move an ellipse in pygame.
This is my code:
import pygame
import pygame
pygame.init()
oW = 400
oH = 500
black = (0,0,0)
red = (255,0,0)
blue = (0,0,255)
gameDisplay = pygame.display.set_mode((800,800))
gameDisplay.fill(black)
Sun = pygame.draw.circle(gameDisplay, red, (400,400), 60)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
#Key input over here
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_a:
oW = oW + 10
if event.key == pygame.K_d:
oH = oH + 10
Orbit = pygame.draw.ellipse(gameDisplay, blue, (200, 250, oW, oH), 1)
pygame.display.update()
How could I make it so that rather than the ellipse constantly duplicating itself and making copies, it's coordinates would just move the original(first one)? Currently, if you run the program below, the ellipse will make copies of itself in the new coordinates rather than modifying the original so there will be a lot of ellipses if you press a or d. After researching online, some people were suggesting putting a black shape over everything and then redrawing it but that's not really what I'm going for here, I just want the shape to update without constantly duplicating itself.
解决方案
这里的问题是您没有绘制背景。当您在下一帧绘制新圆圈时,不会覆盖旧圆圈。只需添加gameDisplay.fill(black)
到循环的开头。如果您愿意,当然可以更改颜色。
推荐阅读
- sql-server - 禁止从 sql server management studio 导出文件中的警告
- c++ - 在 docker 容器中启动 Opc Ua 服务器
- html - 相对定位元素和绝对定位元素
- c# - 如何在 EF 中重用 where 子句
- r - 在ggplot中使用条形图时出现意外的x轴刻度线
- c# - “netsh”命令的替代 -> 对象的使用?
- javascript - 是否可以将全尺寸图像从网站拖放到仅显示缩略图的资源管理器
- spring - 在spring boot中构建jar文件时出错
- python - 在 tkinter 中交互式验证条目小部件内容(第 2 部分 - 更改条目对象的属性)
- mysql - node-mysql res.json(rows) 返回带反斜杠的引号