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

Re: [pygame] Suggestion: make Rect use float coordinates



I was part of a team a while back that created a game in SDL. While there were many things that were nice about SDL, the inability to display half pixels was annoying. Especially if there were things that needed to move slowly across the screen such as clouds in the background. They either had to move fast (~10 pixels a second) or they appeared to "jump" in sharply obvious 1 pixel increments. This is a case where openGL or other textured 3d surfaces come in handy.

~Israel~

Toni Alatalo wrote:

On Fri, 15 Apr 2005, Tobias Pfeiffer wrote:


Tomi Kyöstilä schrieb:


I made a tetris block which has a rect and a speed variable. On every
step I do rect.move_ip(0, speed), but I noticed that if the speed is 1,


What is the use of using 0.x if the screen cannot display half pixels or
the like? Try to put a time.sleep() call before every move, so you can
rather control the speed, I think?



but if you have n things moving at different speeds, or something in the game logic related to speed, that wouldn't give the desired effect

i mean, if you e.g. have things A and B moving across the screen from left to right, with different speeds, it is kinda nice to do something like: (this all being totally untested pseudocode stuff)

class Mover:
   def __init__(self, speed):
       self.speed = speed

   def update(self):
       self.pos += speed

a = Mover(2)
b = Mover(2.5)
movers = [a,b]

while 1:
[m.update() for m in movers]
.. the supposed coordinate system being pixels as in SDL, so that A would move 2 pixels every turn, but B would move 3 on every other


i'm not sure tho if the conversion from positioning floats to pixel ints should be done in pygame, or if it should be left for the application programmer to do, as it is currently .. pygame being a low level library, Rect.x & y are about pixels, not positions of things in the gameworld, or?
at least in systems with scrolling, and also to get screenres independence, a separate coordinate system is needed anyhow (like in some tools we use that the position is a float from 0 to 1)


one thing that came to mind back then on irc when Tomi mentioned that was a Rect subclass that would handle that, something like:

FloatRect(pygame.Rect):
   def set_x(self, x):
       self._x = x #accepts float, no flooring
   def get_x(self):
       return round(self._x) #or just int(), whatever is desired
   x = property(get_x, set_x)

which perhaps would give the effect he was supposing from pygame initially ('ve no clue about the performance tho)



Tobias



~Toni