Okay, so I managed to animate a sprite, but now I'm trying to activate it with a key and not just letting it be animated. What I want is it to be animated AFTER pressing a key and not without pressing any key.
Here is some code that seems to be causing it, I removed a bit of useless code (I hope it's useless). Also, sorry if it's a lot, but I couldn't check it, I'm in a rush to finish other stuff :(.
FULL CODE: pastebin.com/tXwDrua5
def load_image(name):
image = pygame.image.load(name)
return image
class SendSprite(pygame.sprite.Sprite):
def __init__(self):
super(SendSprite, self).__init__()
self.images = []
x = 0
while x <= 56:
self.images.append(pygame.transform.scale(load_image('send' + str(x) + '.png'), (SYNSCALE, SYNSCALE)))
x += 1
y = 57
while y <= 69:
self.images.append(pygame.transform.scale(load_image('send' + str(y) + '.png'), (SYNSCALE, SYNSCALE)))
y += 1
self.index = 0
self.image = self.images[self.index]
self.rect = pygame.Rect(SYNDIST, 0, 350, 350)
def update(self):
'''This method iterates through the elements inside self.images and
displays the next one each tick. For a slower animation, you may want to
consider using a timer of some sort so it updates slower.'''
self.index += 1
if self.index >= len(self.images):
self.index = 0
self.image = self.images[self.index]
def main():
global gameIcon, FPSCLOCK, DISPLAYSURF, BASICFONT, R_SYN_IMG, S_SYN_IMG, SENDSIGNAL
SPR_SYN_SEND = SendSprite()
SENDSIGNAL = pygame.sprite.Group(SPR_SYN_SEND)
pygame.init()
FPSCLOCK = pygame.time.Clock()
pygame.display.set_icon(pygame.image.load('gameicon.png'))
DISPLAYSURF = pygame.display.set_mode((WINWIDTH, WINHEIGHT))
pygame.display.set_caption("The Brain's Synapses")
BASICFONT = pygame.font.Font('freesansbold.ttf', 32)
while True:
runGame()
def runGame():
while True:
DISPLAYSURF.fill(WHITE)
event = pygame.event.poll()
SENDSIGNAL.update()
SENDSIGNAL.draw(DISPLAYSURF)
pygame.display.flip()
if winMode:
DISPLAYSURF.blit(winSurf, winRect)
DISPLAYSURF.blit(winSurf2, winRect2)
pygame.display.update()
FPSCLOCK.tick(FPS)
def terminate():
pygame.quit()
sys.exit()
if __name__ == '__main__':
main()