Python 2.7 - Pygame - move_ip() too granular -


i'm practicing making android app in pygame, , decided classic bubble shooter. have run problem though projectile launched player isn't accurate enough.

def move (self, time_passed):      x = (math.sin(self.angle) * self.speed) * time_passed     y = (math.cos(self.angle) * self.speed) * time_passed     c = self.rect.center     self.rect.center = (c[0]+x, c[1]+y)  def update(self, screen, time_passed):      if self.launched:         if not self.mpos:             self.mpos = pygame.mouse.get_pos()             diffx, diffy = (self.mpos[0]-self.rect.center[0],                             self.mpos[1]-self.rect.center[1])             self.angle = math.atan2(diffx, diffy)         self.move(time_passed) 

the screen , time_passed arguments passed main loop , display , returned value of clock class's tick(60)/1000.0, sake of clarity.

if print values of x , y move() it's accurate: x: 1.0017224084 y: -21.9771825359, or similar depending on mouse is. however, seems pygame or move_ip work integers. can click between 1.00000001 , 1.9999999 , ball shoot in exact spot, being 1 (in reference x coordinate). bad game. there solution can objects move precisely?

edit: realized pasted in wrong code. self.rect.center = (c[0]+x, c[1]+y) self.rect.move_ip(x, y) should be. both methods yield same result, however.

keep track of own positions using precise float values, , instead of incrementally moving rects frame frame, place them @ proper (integer-ized) positions each frame. way don't suffer sum of each frame's rounding error, instead have single rounding involved @ given time.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -