If event.type = pygame.KEYUP: if event.key = pygame.K_a or event.key = pygame.K_d: playerX_Change = 0 if event.key = pygame.K_s or event.key = pygame. If event.type = pygame.KEYDOWN if event.key = pygame.K_a: playerX_Change = -3 if event.key = pygame.K_d: playerX_Change = 3 if event.key = pygame.K_w: playerY_Change =-3 if event.key = pygame.K_s: playerY_Change = 3 You should be detecting KEYDOWN and KEYUP and keeping track of each keys current state (hint, use event. The pygame.time pygame module for monitoring time module defines TIMERRESOLUTION. locals import pygame.init() screen pygame. The pygame.key pygame module to work with the keyboard module lists the keyboard constants and modifiers ( K and MOD ) relating to the key and mod attributes of the KEYDOWN and KEYUP events. #Movement, adjust coordinates according to keys pressed KEYDOWN detects the key going down not being down. pygame event.type KEYUP: 50 bg 'bg.jpg' staticCharacter 'toon.png' import pygame, sys, time from pygame. I was previously using set_repeat for smooth movement but had to ditch it in order to get my shooting mechanic working right. I'm making a space invaders like game and I have an issue that when I'm pressing a to go left on the screen and then immediately press d to go right, if the a key goes up while I'm pressing down d then the movement will stop completely due to the setup of my keyup and keydown events, and this goes for all wasd keys in all directions of movement- if i release s while pressing w, for example, which prevents smooth movement. pygame.quit () sys.exit () for event in (): if event.type pygame.KEYDOWN: if event.key pygame.KSPACE: screen.fill ( (255,000,000)) () The seccond for loop must be change the screen to an red colour whenether you press KSPACE.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |