You should not depend on key repeat for anything whatsoever for gameplay. The behavior you see is exactly how it's supposed to work, and it's useful for typing and nothing else.
you will probably find that get_pressed() will satisfy your needs perfectly. http://www.pygame.org/docs/ref/key.html#pygame.key.get_pressed basically for every update for every movement key, move as needed if that key is pressed. On Sun, Aug 24, 2008 at 9:24 AM, yanom @linuxmail.org <[EMAIL PROTECTED]>wrote: > I have a problem with my pygame project: > i used pygame.key.set_repeat(2,2) to make it so that continually holding > down the left or right arrow keys moves a character. i have a problem > though: > whenever i press a key other than left or right, even if i am still holding > an arrow key, my character stops moving. here is my code: > > > > > import pygame, os, sys > from pygame.locals import * > pygame.init() > clock = pygame.time.Clock()#start the clock > screen = pygame.display.set_mode((640, 680), 0, 32)#create the screen, > conveniently called screen > enemy = pygame.image.load("enemy.sub.png").convert_alpha()#load sub images > player = pygame.image.load("player.sub.png").convert_alpha() > enemyrect = enemy.get_rect() #create rects > playerrect = player.get_rect() > playerrect = playerrect.move(500,500)#move the player sub to the bottom of > the screen > bullet = pygame.image.load("bullet.png").convert_alpha()#load the bullet > image > bulletrect = bullet.get_rect()#create bullet rect > #bulletrect = bulletrect.move(0,780)#move it to the bottom > speed = [2,0] #top speed of the enemysub > pygame.key.set_repeat(2,2) #enable key repeat > while 1:#main game loop > clock.tick(60)#60 fps max > enemyrect=enemyrect.move(speed) #bounce | > if enemyrect.right > 640: speed = [-2, 0]# | > if enemyrect.left <0: speed = [2, 0]# | > if bulletrect.top > 600: > bulletrect.left = enemyrect.left > bulletrect.top = enemyrect.top > else: > bulletrect=bulletrect.move(0,7) > for event in pygame.event.get(): #event query | > if event.type == QUIT:# | > exit()# | > if event.type == KEYDOWN:# | > if event.key == K_RIGHT:# | > playerrect = playerrect.move(2,0)# | > if event.key == K_LEFT:# | > playerrect = playerrect.move(-2,0)# | > screen.fill((0,255,255)) #fill screen > screen.blit(enemy, enemyrect)#blit enemy > screen.blit(player, playerrect)#blit player > screen.blit(bullet,bulletrect)#blit bullet > pygame.display.update() #update screen > > > how do i solve this problem? > > = > Tecpel - Propel Quality Measurement > Wide range of quality sources from Taiwan. > > http://a8-asy.a8ww.net/a8-ads/adftrclick?redirectid=d1e2a9b5471fc3d9949f564a2f7d0acf > > > -- > Powered by Outblaze >
