简体   繁体   English

修改pygame中的椭圆坐标

[英]Modify ellipse coordinates in pygame

I have been trying to move an ellipse in pygame.我一直在尝试在 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.目前,如果您运行下面的程序,椭圆将在新坐标中复制自身而不是修改原始坐标,因此如果您按 a 或 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.在网上研究之后,有些人建议在所有东西上涂上黑色形状,然后重新绘制它,但这并不是我真正想要的,我只是希望形状更新而不不断重复。

The problem here is that you aren't drawing a background.这里的问题是您没有绘制背景。 When you draw a new circle the next frame, the old circle isn't overwritten.当您在下一帧绘制新圆圈时,不会覆盖旧圆圈。 Simply add gameDisplay.fill(black) to the start of your loop.只需将gameDisplay.fill(black)添加到循环的开头即可。 You can of course change the color if you like.如果您愿意,当然可以更改颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM