[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Fwded Post



Thanks twice David.

First for the FpsClock and second for the clear explanation of my problem's
solution.  I used a similar technique for the rotation of the ship, and it
worked well.  I don't know why I didn't think of that for the movement too.
Rookie mistake, I suppose.

I'll let you know how it turns out and I'll post an announcement to the list
as soon as the game's worth looking at. :)

-- rob

----- Original Message -----
From: David Clark <silenus@telus.net>
To: <pygame-users@seul.org>
Sent: Friday, February 08, 2002 12:31 AM
Subject: [pygame] Fwded Post


> "Rob" writes:
>  >
>  > My sprites run beautifully smoothly at some frame rates, and not at all
or
>  > very jerky at others.
>  >
>  > The FpsClock.get_frame_duration() method returns the time in seconds
since
>  > the last frame.  Internally, it uses pygame.get_ticks() to determine
the
>  > time for each frame.  Since pygame.get_ticks() returns milliseconds,
the
>  > most precision that the get_frame_duration() method can return is
>  > thousandths of a second.
>
> Hi Rob. I'm the author of the FpsClock module you're referring to; I
> used it in Twitch, my first game.  I encountered the problem you're
> referring to myself.  My solution was to track the coordinates of my
> sprite separately using floating point values, then use those values
> to create a rect for blitting, collision and updating. For example, my
> code might go...
>
> class Player:
>       width = 20
>       height = 20
>
>       def __init__(self, initial_x, initial_y):
>   self.x = float(initial_x)
>   self.y = float(initial_y)
>   self.rect = pygame.Rect((self.x, self.y, Player.width, Player.height))
>
>       def move(self, delta_x, delta_y):
>   self.x += delta_x
>   self.y += delta_y
>   self.rect.topleft = (self.x, self.y)
>
> See? I am indeed using floats to keep track of my sprite's position,
> but I'm also maintaining a rect for those speed-critical graphics and
> collision purposes.
>
> Good luck with your game.
>
> David Clark
> Futility in #pygame at irc.openprojects.net
>
> ____________________________________
> pygame mailing list
> pygame-users@seul.org
> http://pygame.seul.org


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org