animation - Pygame/Python. Left seems to move faster than right. Why? -


i've coded bit c++ , java during past few years , i've started python. goal make game. i've noticed, however, @ basic animation part of player moving left , right, left "speed" faster right "speed". although "speed" values same.

the update function:

def update(self,dt,game):     last=self.rect.copy()       self.time+=dt       if self.left:        self.rect.x-=300*dt     if self.right:        self.rect.x+=300*dt 

i've noticed if change left speed 250, instead of 300, run same. example if press both left , right keys player stay on exact same spot. if have left , right speed both @ 300. player move left.

my game loop:

while 1:         dt=clock.tick(60)         if dt>1000/60.0:             dt=1000/60.0          event in pygame.event.get():             if event.type==pygame.quit:                 return             if event.type==pygame.keydown , event.key==pygame.k_escape:                 return             if event.type==pygame.keydown , event.key==pygame.k_left:                 self.player.left=true                 self.player.image=self.player.leftimages[1]             if event.type==pygame.keydown , event.key==pygame.k_right:                 self.player.right=true                 self.player.image=self.player.rightimages[1]             if event.type==pygame.keyup , event.key==pygame.k_left:                 self.player.left=false                 self.player.image=self.player.leftimages[0]             if event.type==pygame.keyup , event.key==pygame.k_right:                 self.player.right=false                 self.player.image=self.player.rightimages[0]          self.tilemap.update(dt/1000.0,self)         screen.fill((0,0,0))          self.tilemap.draw(screen)         pygame.display.update() 

i'm using tmx library richard jones able import map made in tiled map editor. hope sufficient information answer weird question. i've asked other programming friend , finds weird.

some code might off, beacause i've copy pasted original code has more stuff it. i've extracted basic parts control movement.

thank time!

have tried printing value of dt update function? if speed different when move left when move right, must changing (backed saying holding left , right @ same time results in no movement).

based on own testing, looks pygame.time.clock.tick() returns integer value representing number of milliseconds have passed since last call. attempt correct value (dt=1000/60.0), getting floating point value. suspect reason, timer off when either pressing left or right, , attempts correct manually causing different dt value passed in update function during these situations.

the pygame documentation suggests pygame.time.clock.tick_busy_loop() if need more accurate (but cpu intensive) timer.

http://www.pygame.org/docs/ref/time.html#pygame.time.clock.tick_busy_loop


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -