python - 为什么我的 pygame 圈子不断消失并重新产生?

标签 python pygame display

当我运行这个程序时,我希望游戏在随机位置生成一个较大的可移动点和数百个较小的不可移动点。然而,当我运行该程序时,较小的点不断消失和重生。我认为这与 pygame.display.update() 函数有关,但我不完全确定。如何解决这个问题?

from pygame import *
import random as rd

p_1_x = 200
p_1_y = 200
p_1_change_x = 0

init()
screen = display.set_mode((800, 600))


def p_1(x, y):
    player_1 = draw.circle(screen, (0, 0, 0), (x, y), 15)


def drawwing():
    for i in range(0, 250):
        x = rd.randint(100, 700)
        y = rd.randint(100, 500)
        dot = draw.circle(screen, (55, 255, 155), (x, y), 5)


while True:
    for events in event.get():
        if events.type == QUIT:
            quit()
        if events.type == KEYDOWN:
            if events.key == K_RIGHT:
                p_1_change_x = 1
            if events.key == K_LEFT:
                p_1_change_x = -1

        if events.type == KEYUP:
            if events.key == K_RIGHT or K_LEFT:
                p_1_change_x = 0
                p_1_change_y = 0

    screen.fill((255, 255, 255))
    p_1_x += p_1_change_x

    p_1(p_1_x, p_1_y)
    display.update()
    drawwing()
    display.update()

最佳答案

如果你想要固定点,请使用类似这样的东西:

dots = list((rd.randint(100,700),rd.randint(100,500)) for i in range(0,250))

def drawwing():
    for x,y in dots:
        draw.circle(screen, (55, 255, 155), (x, y), 5)

关于python - 为什么我的 pygame 圈子不断消失并重新产生?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63912237/

相关文章:

python - 比较分配给两个字典中一个键的多个值

Python lstat 给出的值与系统 stat 不同

python - 使用 Bottle.py,如何正确渲染模板的静态文件请求?

python - 为什么我的 pygame 窗口在关闭之前只保持打开一秒钟?

Python、pygame、py2exe

html - 切换隐藏元素的 CSS 不透明度过渡

python - 调试 Pandas 中的打印 DataFrame 问题

python - 获取递归错误: maximum recursion depth exceeded in comparison

html - 如何使用内联 block 属性将文本放在背景图像下方

android - CSS 显示 : none not working on Samsung S5 mini