[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] [Pygame] How can I have an accurate timing when I am showing an image?



hey,

you should probably load a number of images in advance.  Otherwise
reading them from disk, the time to do so could be variable.

Maybe load the next image after the display.flip call.

Or, can you compress all of the images, and then load them all into
memory?  Might take a lot of memory, but would remove a little of the
OS dependant guesswork.  Note that pygame can load png files stored in
StringIO variables.

cu,


On Sat, May 24, 2008 at 5:38 AM, Francesco Martino
<francesco.k@xxxxxxxxx> wrote:
> I am using Pygame for building a psychological experiment.
> The code should do something very easy: it should display an image for
> a limited amount of time, then show a blank screen and then another
> image. Images are stored as bitmap files (470 Kb each).
> The main requisite for this program is that timing needs to be very
> accurate, namely if I say that an image should be displayed for 800
> msec the amount of error should be as little as possibile.
>
> The code is very simple: each image is shown using
>
>        startTime = time.time()
>        test = image.load(image1).convert() #image1 is the name of the file
>        surf.blit(test, (0,0))
>        display.update()
>        pygame.time.delay(TIME_TEST_IMAGE)
>        stopTime = time.time()
>        img_length = stopTime - startTime
>
> Using the Python time module, I see that error is acceptable for my
> purposes (the range is TIME_TEST_image +/-1, plus a costant error of
> 45 msec, so image is displayed for about 845 msec) in most of the
> cases. Unfortunately, sometimes the image is displayed for a shorter
> time (with a costant error of 11 msec, so image is displayed for about
> 811 msec) Since it happens with an irregular rate, it is very
> difficult to understand the reason. Has anyone some ideas? Is there a
> better way to display images for a fixed period of time with pygame?
>
> Thank you for any idea
> Francesco
>