[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[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