0

I am making a pygame game and need the variable "img" to cycle through multiple slides to make a walking animation, but all the timers i can find made with python/pygame delay the program which i don't want.

  • possible duplicate of [Move an object every few seconds in Pygame](http://stackoverflow.com/questions/23368999/move-an-object-every-few-seconds-in-pygame) – sloth Jun 16 '14 at 06:42

2 Answers2

0

You can measure time with Python's time module. You could do something like the following:

import time

t = time.clock()
deltaT = 1 #time between updates, in seconds
while True: #inside the game loop...
    if (time.clock() - t) > deltaT:
        #change your image
        t = time.clock()

Although if you're animating sprites, you might have better luck looking for animation modules for pygame.

Clyde W
  • 123
  • 7
0

You can do something like the following:

import time, pygame
from pygame.locals import *
images = ['img1.jpg', 'img2.jpg', 'img3.jpg', 'img4.jpg']
pygame.init()
screen = pygame.display.set_mode((1024, 1280))
i = 0

x = time.time()

while True:
    screen.blit(images[i]) #Create the image, this syntax is wrong
    screen.fill((255, 255, 255))
    if i != 3:
        i+=1
    elif i == 4:
        i = 0
A.J. Uppal
  • 19,117
  • 6
  • 45
  • 76