暂时从python中删除图像

时间:2015-10-14 16:17:27

标签: python pygame

我希望玩家触摸后不会渲染对象。

if dollary + dollar_width > y:
        if dollary < y + smiley_height:
            if dollarx > x and dollarx < x + smiley_width or dollarx + dollar_width > x and dollarx + dollar_width < x + smiley_width:
                points += 1 

当美元(玩偶和美元)和玩家重叠时,这给玩家(y和x)点数,但是我希望玩家接触到美元后消失。

我试过了:

os.remove("file.gif")

它删除了实际文件,而不是渲染它。

编辑:这是我的游戏循环:

def game_loop():

x = (display_width * 0.5 - (smiley_width/2))
y = (display_height * 0.8)

x_change = 0

thing_width = 100
thing_height = 100
thing_startx = random.randrange(0, (display_width - thing_width))
thing_starty = -600
thing_speed = 3

dollarx = thing_startx
dollary = thing_starty - 90
dollar_height = 87
dollar_width = 82

dodged = 0
points = 0

gameExit = False

while not gameExit:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                x_change = -5
            elif event.key == pygame.K_RIGHT:
                x_change = 5
        if event.type == pygame.KEYUP:
            if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
                x_change = 0

    x += x_change

    gameDisplay.fill(white)

    #things(thingx, thingy, thingw, thingh, color)
    things(thing_startx, thing_starty, thing_width, thing_height, red)
    thing_starty += thing_speed

    dollar(dollarx,dollary)
    dollary += thing_speed
    smiley (x,y)
    things_dodged(dodged)
    score(points)

    if x > display_width - smiley_width or x < 0:
        die()

    if dollary > display_height:
        thing_speed += 1
        thing_starty = 0 - thing_height
        thing_startx = random.randrange(0, display_width)
        dollarx = thing_startx
        dollary = thing_starty - 90
        dodged += 1
        thing_width += (dodged * 0.9)

    if y + smiley_height > thing_starty:
        if y < thing_starty + thing_height:
            if x > thing_startx and x < thing_startx + thing_width or x + smiley_width > thing_startx and x + smiley_width < thing_startx + thing_width:
                die()

    if dollary + dollar_width > y:
        if dollary < y + smiley_height:
            if dollarx > x and dollarx < x + smiley_width or dollarx + dollar_width > x and dollarx + dollar_width < x + smiley_width:
                points += 1

    pygame.display.update()
    clock.tick(60)

这有点乱,但我对此很新,所以欢迎任何指针

1 个答案:

答案 0 :(得分:0)

你应该有一个显示循环。一旦一帧,你清除屏幕,然后将所有图像blit到它。只需不要将此图像blit到下一帧的屏幕上。