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

Re: [pygame] Rects and subpixel values



> What's the solution? Should Rect.left be able to hold a float, but
> only pass an int to SDL?
> 
> Ugh. Ever notice that when you type out a problem you're having, the
> solution seems obvious? The solution, I suppose, is to keep track of
> the 'real' x and y coordinates in an extra pair of variables -
> player.x and player.y (both as floats), and only do:
> 
> player.rect.topleft = (int(player.x), int(player.y))
> 
> before drawing and collision detection. Hmmm... that should work.
> 
> Any thoughts? Has anyone tried this stuff before?


hello david. the idea to use floats is definitely correct.
this type of game timing is used in 3D a lot more, and works
well since everything is positioned with floats anyways.

most 2D games try to hold the machine to a consistent framerate,
but the idea to run at the fastest rate possible for the machine
is always nice.

as a nice shortcut for you. throughout most of pygame where 
numeric arguments are needed, they will be automatically 
converted from float (and long) numbers. this works for Rect too,
>>> position = 10.5, 2.2
>>> player.rect.topleft = position
>>> print player.rect.topleft
(10, 2)

saves you from hand-converting, and makes it look a bit cleaner.

i'd like to hear how it goes. you'll just need to keep some
separate floating position data. the only other option would
be some simple fixed point data, but outside of C any
gains from all interger math would likely be lost.





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