title: How to use a while loop within a class in pygame?
body: <p>I'm trying to make an instance class (Block) spawn when the mouse is clicked and fade out slowly, and i want to be able to spawn an infinite number of blocks that fade out provided that the mouse is clicked fast enough. </p>
  
  <p>To do this, I want to initiate the fade() function when the instance is first spawned and set ticks to 255 and set the alpha to ticks.</p>
  
  <p>However, when using a while loop, the function completes itself without updating the display because the program gets constrained to the while loop in the fade() function.</p>
  
  <p>Can someone help me with calling the fade function 255 times per instance?</p>
  
  <pre><code>import pygame,sys,time,Blockm
  from pygame.locals import *
  black,white=(0,0,0),(255,255,255)
  size=w,h=1400,800
  screen=pygame.display.set_mode(size)
  pygame.init()
  
  class Block(object):
  
      sprite = None
  
      def __init__(self, x, y):
          if not Block.sprite:
              Block.sprite = pygame.image.load("Block.png").convert_alpha()
          self.rect = Block.sprite.get_rect(top=y, left=x)
          self.fade()
  
      def fade(self):
          ticks=255
          Block.sprite.set_alpha(ticks)
          while ticks!=0:
              ticks-=1
              print(ticks)
  
  
  
  while True:
      blocks = []
      mmraw=pygame.mouse.get_pos()
      mmx,mmy=mmraw[0]-(pygame.image.load("Block.png").get_width())/2,mmraw[1]-(pygame.image.load("Block.png").get_width())/2
      for event in pygame.event.get():
          if event.type== pygame.QUIT:
              pygame.quit()
              sys.exit()
          if event.type == pygame.MOUSEBUTTONDOWN:
              print('click')
              blocks.append(Block(mmx,mmy))
  
      for block in blocks:
          screen.blit(block.sprite, block.rect)
          print('trying to blit')
          print(Block.sprite.get_offset())
      pygame.display.update()
  </code></pre>