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

Re: [pygame] Re:



> ----- Original Message -----
> From: "Charlie Nolan" <funnyman3595@xxxxxxxxx>
> To: pygame-users@xxxxxxxx
> Subject: [pygame] Re:
> Date: Sun, 24 Aug 2008 11:48:25 -0500
> 
> 
> For continuous movement, it's generally better to ignore key events
> and just check to see which keys are down (via pygame.key.get_pressed)
> once every tick.
> 
> On 8/24/08, yanom @linuxmail.org <yanom@xxxxxxxxxxxxx> 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
> >

>
how does pygame.key.get_pressed() work?

=
Buy Corporate Awards
Sophisticated Glass/Crystal/Marble Corporate Awards. Free Engraving.
http://a8-asy.a8ww.net/a8-ads/adftrclick?redirectid=a3690ad8b41e8f4062721e2684b4a423


-- 
Powered by Outblaze