How do I stop this from disappearing?

Viewed 44

I'm trying to do a pygame code here, but it isn't working how I want to, I want to fix this circle on the screen, can you guys help me please?

while True:
    clock.tick(60)

    window.blit(bg, (0,0))

    # circulo #

    for event in pg.event.get():
        if event.type == pg.KEYDOWN:
            if event.key == pg.K_q:
                clock.tick(1)
                pg.draw.circle(window, (5,5,5), [120, 120], 60, 1)
                continue
1 Answers

The problem is that you're (probably) clearing the screen every frame with the window.blit(bg, (0,0)).

Then if the user presses q, for that frame only, a circle is drawn. After a few more milliseconds (maybe less than 1), the background is re-drawn. So depending on your system, the human may never notice the circle being drawn.

One way to fix this, is to just set a boolean "flag" so the circle is re-painted until the flag changes back again.

draw_circle = False   # Should the circle be drawn?

while True:
    clock.tick(60)

    # re-draw the scene
    window.blit(bg, (0,0))

    # circulo #
    if draw_circle:
        pg.draw.circle(window, (5,5,5), [120, 120], 60, 1)

    for event in pg.event.get():
        if event.type == pg.KEYDOWN:
            if event.key == pg.K_q:
                draw_circle = not draw_circle  # toggle circle on/off
Related