0

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()
Archos331
  • 1
  • 3
  • The issue I addressed in my answer was already taken care of in your actual code. Because of this, i'm deleteting my answer. If you want to post your code, as well as explain where your MOVERATE is defined, I'll spend a couple more minutes on it – David Jay Brady Mar 11 '16 at 02:21
  • @DavidJayBrady I put up a pastebin with all of the code. Please help. – Archos331 Mar 12 '16 at 16:56
  • Hey man, I'm sorry I can't get around to it now. Its my finals week so I've been hitting the books hard. I'm less busy come Friday. If its still needing doing then, message me and I'll give it another shot. But until then I"m just super duper busy – David Jay Brady Mar 14 '16 at 05:39
  • @DavidJayBrady Ohhh okay, well I'm only asking for help so you finish your stuff first then help me :D – Archos331 Mar 14 '16 at 18:56

0 Answers0