2015-10-14 71 views
0

我想要一個對象在玩家接觸它之後不渲染。暫時從python中刪除圖像

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)指出,當美元(dollary和dollarx)和玩家的重疊,但我希望美元儘快玩家接觸它dissapear。

我想:

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) 

這是一個有點混亂,但我很新的這一點,所以任何指針歡迎

+0

看着os.remove調用文檔,調用正在做它應該http://www.tutorialspoint.com/python/os_remove.htm。你需要一種方法來隱藏python和pygame中的顯示,而不是刪除實際的文件。請參閱文檔https://media.readthedocs.org/pdf/pygame/latest/pygame.pdf以查找隱藏對象的更好方法。 – VC1

+0

您需要停止在事件循環中繪製它。向我們展示您的事件循環 – cmd

+0

我在我的遊戲循環中複製 – thepinkadmiral

回答

0

你應該有一個顯示循環。一旦一個框架,你清除屏幕,然後將所有圖像blit到它。只要不將此圖像粘貼到下一幀的屏幕上即可。