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

[pygame] Suggestion: make Rect use float coordinates



Hello,

I just got pygame yesterday to see what's it like and what can I do with it. I started a tetris-like game project to see pygame's features and such.

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, the block moves too fast, so I tried 0.1. The block didn't move at all. Then I tested different values; 0.5: nope, 0.9: nope, 1: moved, but too fast as stated before. When I tried a value of 1.9, it was surprising. It moved at the same speed as with a value of 1, so with my amazing deduction skill (;)) I deduced that move and move_ip floored the value to an integer.

On the IRC channel antont thought that the value would be needed as an integer in some other place in pygame (he pointed out blitting as an example), so that would be why it's stored as an integer. If that's the case, IMHO the value should be floored (or rounded?) only where needed (in the blit method in this case). I don't know how it would affect the performance of blitting if it's done there, any info on this?

ATM I use a position variable as a workaround. I add the speed to position[1] and then do rect.topleft = position. So if the speed was 0.1, the rect's position stays the same for 10 steps (due to the flooring) and only then move 1 pixel. The workaround isn't too complicated, but this would be a nice change in pygame if it doesn't affect it's performance too much(?).

I haven't found other reasons why it is like it is, but it's very possible that I haven't thought of something, so if you have any ideas or opinions on the matter, please reply.

- dOb