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

Re: [pygame] Question about timing



Francesco,

The output looks like an integer to me - an integer representing the millisecond count.  Python agrees it is an integer:

>>> type(clock.get_time())
<type 'int'>

Also, I'm assuming your indentation is off on the second clock.get_time() call.  The main problem I see other than that is that you need to call "clock.tick()", not "clock.tick", which just returns the method itself.  And if you never call clock.tick(), clock.get_time() will always return the same thing (as seen in your output).

--Paul


On Mon, May 12, 2008 at 6:57 AM, Francesco Martino <francesco.k@xxxxxxxxx> wrote:
Sorry if my question is silly, but maybe I didn't catch very much some question about pygame.time module.

I am writing an application which needs to very accurate about timing; it displays sequentially some images, each one of them remaining on the screen for a constant time T.
This is a part of the code I wrote to understand how time module works:

*********************************************************************
clock = time.Clock()

while 1:
   
    clock.tick
    msec = clock.get_time()
    print "1. msec = %i" %msec  # these lines has been written just to see what is returned by get_time()
   
    for event in pygame.event.get():
        if event.type == QUIT:
            exit()
           
    surf.fill((255,255,255,255))  # these lines has been written just to see what is returned by get_time()

msec = clock.get_time()
    print "2. msec = %i" %msec
*********************************************************************

This is the output of th application:

1.msec = 1767859565
2.msec = 1767859565
1.msec = 1767859565
2.msec = 1767859565
1.msec = 1767859565
2.msec = 1767859565
....

My problem is that I cannot understand what type is returned by get.time():

at http://snipurl.com/28h08, it is reported that this method returns an int
at http://snipurl.com/28h0t , it is reported that this method returns milliseconds.

My other question is: is it possibile to transform milliseconds type into an int?

I am using Pygame 1.7.1

Thank you in advance for any help you can provide me,
Francesco