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

Re: [pygame] Float precision



Hi. If you still have problens with precision, you may want to use round() before converting to integer:

               self.rect.centerx = int(round(self.xx))
               self.rect.centery = int(round(self.yy))

or just (with same results):

               self.rect.centerx = int(self.xx + 0.5)
               self.rect.centery = int(self.yy + 0.5)

  Marcel


2008/7/4 OsKaR <oscartorres10@xxxxxxxxx>:
Thanks John I will use this till I find a new solution

2008/7/4 John Leach <john.leach@xxxxxxxxxxxxx>:

Yes I see this.
I think most of the problem is here
               self.rect.centerx += dx
               self.rect.centery += dy
maybe centerx and centery need to be integers?
I had better luck when I changed it to like this
               self.xx += dx
               self.yy += dy
               self.rect.centerx = int(self.xx)
               self.rect.centery = int(self.yy)
where self.xx and self.yy are floats.
It was still not perfect but much better than before.
John