赞
踩
刚学习python+pygame就遇到了个棘手的问题——pygame.event.get()
这是官方注释
pygame.event. get ( )This will get all the messages and remove them from the queue. If a type or sequence of types is given only those messages will be removed from the queue.
If you are only taking specific events from the queue, be aware that the queue could eventually fill up with the events you are not interested.
写进代码里思路就乱了,比如这个例子- background_image_filename = 'sushiplate.jpg'
-
- import pygame
- from pygame.locals import *
- from sys import exit
-
- pygame.init()
- screen = pygame.display.set_mode((640, 480), 0, 32)
- background = pygame.image.load(background_image_filename).convert()
-
- x, y = 0, 0
- move_x, move_y = 0, 0
-
- while True:
- for event in pygame.event.get():
- if event.type == QUIT:
- exit()
- if event.type == KEYDOWN:
- #键盘有按下?
- if event.key == K_LEFT:
- #按下的是左方向键的话,把x坐标减一
- move_x = -1
- elif event.key == K_RIGHT:
- #右方向键则加一
- move_x = 1
- elif event.key == K_UP:
- #类似了
- move_y = -1
- elif event.key == K_DOWN:
- move_y = 1
- elif event.type == KEYUP:
- #如果用户放开了键盘,图就不要动了
- move_x = 0
- move_y = 0
-
- #计算出新的坐标
- x+= move_x
- y+= move_y
-
- screen.fill((0,0,0))
- screen.blit(background, (x,y))
- #在新的位置上画图
- pygame.display.update()
- import pygame,time
- pygame.init()
- screen = pygame.display.set_mode((640, 480), 0, 32)
- pygame.display.update()
- clock=pygame.time.Clock()
- outclock=pygame.time.Clock()
- while True:
- tt=0
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- exit()
- print 'infor: ',clock.tick()
- print 'time: ',time.time()
- print str(event)
- tt+=1
- pygame.time.delay(200)
- print '************************************'
- print tt
- print 'out: ',outclock.tick()
- print 'outtime: ',time.time()
在键盘上乱按一通,输出是介个样子
- Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
- Type "copyright", "credits" or "license()" for more information.
- >>> ================================ RESTART ================================
- >>>
- infor: 7
- time: 1374995035.72
- <Event(17-VideoExpose {})>
- infor: 239
- time: 1374995035.96
- <Event(1-ActiveEvent {'state': 1, 'gain': 0})>
- ************************************
- 2
- out: 491
- outtime: 1374995036.2
- infor: 261
- time: 1374995036.21
- <Event(1-ActiveEvent {'state': 1, 'gain': 1})>
- infor: 239
- time: 1374995036.46
- <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (203, 96), 'rel': (203, 96)})>
- ************************************
- 2
- out: 504
- outtime: 1374995036.71
- infor: 263
- time: 1374995036.73
- <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (202, 99), 'rel': (-1, 3)})>
- infor: 246
- time: 1374995036.97
- <Event(2-KeyDown {'scancode': 32, 'key': 100, 'unicode': u'd', 'mod': 4096})>
- ************************************
- 2
- out: 504
- outtime: 1374995037.21
- infor: 260
- time: 1374995037.23
- <Event(2-KeyDown {'scancode': 33, 'key': 102, 'unicode': u'f', 'mod': 4096})>
- infor: 235
- time: 1374995037.47
- <Event(3-KeyUp {'scancode': 32, 'key': 100, 'mod': 4096})>
- infor: 251
- time: 1374995037.71
- <Event(2-KeyDown {'scancode': 34, 'key': 103, 'unicode': u'g', 'mod': 4096})>
- infor: 248
- time: 1374995037.96
- <Event(3-KeyUp {'scancode': 33, 'key': 102, 'mod': 4096})>
- infor: 249
- time: 1374995038.21
- <Event(2-KeyDown {'scancode': 35, 'key': 104, 'unicode': u'h', 'mod': 4096})>
- infor: 242
- time: 1374995038.46
- <Event(2-KeyDown {'scancode': 20, 'key': 116, 'unicode': u't', 'mod': 4096})>
- infor: 256
- time: 1374995038.71
- <Event(3-KeyUp {'scancode': 34, 'key': 103, 'mod': 4096})>
- infor: 250
- time: 1374995038.96
- <Event(3-KeyUp {'scancode': 20, 'key': 116, 'mod': 4096})>
- infor: 243
- time: 1374995039.2
- <Event(2-KeyDown {'scancode': 21, 'key': 121, 'unicode': u'y', 'mod': 4096})>
- infor: 248
- time: 1374995039.45
- <Event(2-KeyDown {'scancode': 36, 'key': 106, 'unicode': u'j', 'mod': 4096})>
- infor: 242
- time: 1374995039.69
- <Event(3-KeyUp {'scancode': 35, 'key': 104, 'mod': 4096})>
- infor: 245
- time: 1374995039.94
- <Event(3-KeyUp {'scancode': 21, 'key': 121, 'mod': 4096})>
- infor: 251
- time: 1374995040.19
- <Event(2-KeyDown {'scancode': 37, 'key': 107, 'unicode': u'k', 'mod': 4096})>
- infor: 242
- time: 1374995040.43
- <Event(2-KeyDown {'scancode': 22, 'key': 117, 'unicode': u'u', 'mod': 4096})>
- infor: 250
- time: 1374995040.68
- <Event(3-KeyUp {'scancode': 36, 'key': 106, 'mod': 4096})>
- ************************************
- 15
- out: 3728
- outtime: 1374995040.94
- infor: 286
- time: 1374995040.97
- <Event(3-KeyUp {'scancode': 22, 'key': 117, 'mod': 4096})>
- infor: 249
- time: 1374995041.22
- <Event(2-KeyDown {'scancode': 38, 'key': 108, 'unicode': u'l', 'mod': 4096})>
- infor: 244
- time: 1374995041.46
- <Event(3-KeyUp {'scancode': 37, 'key': 107, 'mod': 4096})>
- infor: 249
- time: 1374995041.71
- <Event(2-KeyDown {'scancode': 39, 'key': 59, 'unicode': u';', 'mod': 4096})>
- infor: 243
- time: 1374995041.95
- <Event(2-KeyDown {'scancode': 24, 'key': 111, 'unicode': u'o', 'mod': 4096})>
- infor: 242
- time: 1374995042.19
- <Event(3-KeyUp {'scancode': 39, 'key': 59, 'mod': 4096})>
- infor: 247
- time: 1374995042.44
- <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (202, 98), 'rel': (0, -1)})>
- infor: 247
- time: 1374995042.69
- <Event(3-KeyUp {'scancode': 24, 'key': 111, 'mod': 4096})>
- infor: 245
- time: 1374995042.93
- <Event(2-KeyDown {'scancode': 37, 'key': 107, 'unicode': u'k', 'mod': 4096})>
- infor: 242
- time: 1374995043.18
- <Event(3-KeyUp {'scancode': 38, 'key': 108, 'mod': 4096})>
- infor: 250
- time: 1374995043.42
- <Event(2-KeyDown {'scancode': 36, 'key': 106, 'unicode': u'j', 'mod': 4096})>
- infor: 242
- time: 1374995043.67
- <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (202, 97), 'rel': (0, -1)})>
- infor: 251
- time: 1374995043.92
- <Event(3-KeyUp {'scancode': 37, 'key': 107, 'mod': 4096})>
- infor: 247
- time: 1374995044.16
- <Event(2-KeyDown {'scancode': 35, 'key': 104, 'unicode': u'h', 'mod': 4096})>
- infor: 242
- time: 1374995044.4
- <Event(3-KeyUp {'scancode': 36, 'key': 106, 'mod': 4096})>
- infor: 247
- time: 1374995044.65
- <Event(2-KeyDown {'scancode': 34, 'key': 103, 'unicode': u'g', 'mod': 4096})>
- infor: 244
- time: 1374995044.9
- <Event(3-KeyUp {'scancode': 35, 'key': 104, 'mod': 4096})>
- infor: 249
- time: 1374995045.15
- <Event(2-KeyDown {'scancode': 33, 'key': 102, 'unicode': u'f', 'mod': 4096})>
- infor: 246
- time: 1374995045.39
- <Event(3-KeyUp {'scancode': 34, 'key': 103, 'mod': 4096})>
- infor: 251
- time: 1374995045.64
- <Event(2-KeyDown {'scancode': 32, 'key': 100, 'unicode': u'd', 'mod': 4096})>
- infor: 246
- time: 1374995045.89
- <Event(3-KeyUp {'scancode': 33, 'key': 102, 'mod': 4096})>
- infor: 251
- time: 1374995046.14
- <Event(2-KeyDown {'scancode': 31, 'key': 115, 'unicode': u's', 'mod': 4096})>
- infor: 241
- time: 1374995046.38
- <Event(3-KeyUp {'scancode': 32, 'key': 100, 'mod': 4096})>
- infor: 246
- time: 1374995046.62
- <Event(2-KeyDown {'scancode': 30, 'key': 97, 'unicode': u'a', 'mod': 4096})>
- infor: 240
- time: 1374995046.87
- <Event(3-KeyUp {'scancode': 31, 'key': 115, 'mod': 4096})>
- infor: 249
- time: 1374995047.12
- <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (202, 95), 'rel': (0, -2)})>
- infor: 251
- time: 1374995047.37
- <Event(2-KeyDown {'scancode': 31, 'key': 115, 'unicode': u's', 'mod': 4096})>
- infor: 244
- time: 1374995047.61
- <Event(3-KeyUp {'scancode': 30, 'key': 97, 'mod': 4096})>
- infor: 242
- time: 1374995047.85
- <Event(2-KeyDown {'scancode': 32, 'key': 100, 'unicode': u'd', 'mod': 4096})>
- infor: 241
- time: 1374995048.09
- <Event(3-KeyUp {'scancode': 31, 'key': 115, 'mod': 4096})>
- infor: 243
- time: 1374995048.34
- <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (203, 94), 'rel': (1, -1)})>
- infor: 242
- time: 1374995048.58
- <Event(2-KeyDown {'scancode': 33, 'key': 102, 'unicode': u'f', 'mod': 4096})>
- infor: 249
- time: 1374995048.83
- <Event(3-KeyUp {'scancode': 32, 'key': 100, 'mod': 4096})>
- infor: 246
- time: 1374995049.07
- <Event(2-KeyDown {'scancode': 34, 'key': 103, 'unicode': u'g', 'mod': 4096})>
- infor: 250
- time: 1374995049.32
- <Event(3-KeyUp {'scancode': 33, 'key': 102, 'mod': 4096})>
- infor: 244
- time: 1374995049.57
- <Event(2-KeyDown {'scancode': 35, 'key': 104, 'unicode': u'h', 'mod': 4096})>
- infor: 241
- time: 1374995049.81
- <Event(2-KeyDown {'scancode': 49, 'key': 110, 'unicode': u'n', 'mod': 4096})>
- infor: 242
- time: 1374995050.05
- <Event(3-KeyUp {'scancode': 34, 'key': 103, 'mod': 4096})>
- infor: 242
- time: 1374995050.29
- <Event(2-KeyDown {'scancode': 50, 'key': 109, 'unicode': u'm', 'mod': 4096})>
- infor: 242
- time: 1374995050.54
- <Event(3-KeyUp {'scancode': 49, 'key': 110, 'mod': 4096})>
- infor: 249
- time: 1374995050.79
- <Event(2-KeyDown {'scancode': 36, 'key': 106, 'unicode': u'j', 'mod': 4096})>
- infor: 243
- time: 1374995051.03
- <Event(3-KeyUp {'scancode': 35, 'key': 104, 'mod': 4096})>
- infor: 247
- time: 1374995051.28
- <Event(2-KeyDown {'scancode': 51, 'key': 44, 'unicode': u',', 'mod': 4096})>
- infor: 243
- time: 1374995051.52
- <Event(3-KeyUp {'scancode': 36, 'key': 106, 'mod': 4096})>
- infor: 242
- time: 1374995051.76
- <Event(3-KeyUp {'scancode': 50, 'key': 109, 'mod': 4096})>
- infor: 247
- time: 1374995052.01
- <Event(2-KeyDown {'scancode': 37, 'key': 107, 'unicode': u'k', 'mod': 4096})>
- infor: 243
- time: 1374995052.25
- <Event(3-KeyUp {'scancode': 51, 'key': 44, 'mod': 4096})>
- infor: 248
- time: 1374995052.5
- <Event(3-KeyUp {'scancode': 37, 'key': 107, 'mod': 4096})>
- infor: 242
- time: 1374995052.74
- <Event(2-KeyDown {'scancode': 38, 'key': 108, 'unicode': u'l', 'mod': 4096})>
- infor: 249
- time: 1374995052.99
- <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (204, 94), 'rel': (1, 0)})>
- infor: 241
- time: 1374995053.23
- <Event(2-KeyDown {'scancode': 37, 'key': 107, 'unicode': u'k', 'mod': 4096})>
- infor: 242
- time: 1374995053.47
- <Event(3-KeyUp {'scancode': 38, 'key': 108, 'mod': 4096})>
- infor: 246
- time: 1374995053.71
- <Event(2-KeyDown {'scancode': 36, 'key': 106, 'unicode': u'j', 'mod': 4096})>
- infor: 243
- time: 1374995053.96
- <Event(2-KeyDown {'scancode': 35, 'key': 104, 'unicode': u'h', 'mod': 4096})>
- infor: 247
- time: 1374995054.21
- <Event(3-KeyUp {'scancode': 37, 'key': 107, 'mod': 4096})>
- infor: 245
- time: 1374995054.45
- <Event(2-KeyDown {'scancode': 34, 'key': 103, 'unicode': u'g', 'mod': 4096})>
- infor: 248
- time: 1374995054.7
- <Event(3-KeyUp {'scancode': 36, 'key': 106, 'mod': 4096})>
- infor: 242
- time: 1374995054.94
- <Event(2-KeyDown {'scancode': 33, 'key': 102, 'unicode': u'f', 'mod': 4096})>
- infor: 252
- time: 1374995055.19
- <Event(3-KeyUp {'scancode': 35, 'key': 104, 'mod': 4096})>
- infor: 242
- time: 1374995055.44
- <Event(2-KeyDown {'scancode': 32, 'key': 100, 'unicode': u'd', 'mod': 4096})>
- infor: 253
- time: 1374995055.69
- <Event(3-KeyUp {'scancode': 34, 'key': 103, 'mod': 4096})>
- infor: 240
- time: 1374995055.93
- <Event(3-KeyUp {'scancode': 33, 'key': 102, 'mod': 4096})>
- infor: 244
- time: 1374995056.17
- <Event(2-KeyDown {'scancode': 31, 'key': 115, 'unicode': u's', 'mod': 4096})>
- infor: 246
- time: 1374995056.42
- <Event(3-KeyUp {'scancode': 32, 'key': 100, 'mod': 4096})>
- infor: 244
- time: 1374995056.67
- <Event(2-KeyDown {'scancode': 30, 'key': 97, 'unicode': u'a', 'mod': 4096})>
- infor: 250
- time: 1374995056.91
- <Event(3-KeyUp {'scancode': 31, 'key': 115, 'mod': 4096})>
- infor: 245
- time: 1374995057.16
- <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (205, 92), 'rel': (1, -2)})>
- infor: 242
- time: 1374995057.4
- <Event(2-KeyDown {'scancode': 31, 'key': 115, 'unicode': u's', 'mod': 4096})>
- infor: 241
- time: 1374995057.64
- <Event(3-KeyUp {'scancode': 30, 'key': 97, 'mod': 4096})>
- infor: 241
- time: 1374995057.88
- <Event(2-KeyDown {'scancode': 32, 'key': 100, 'unicode': u'd', 'mod': 4096})>
- infor: 243
- time: 1374995058.12
- <Event(3-KeyUp {'scancode': 31, 'key': 115, 'mod': 4096})>
- infor: 246
- time: 1374995058.37
- <Event(2-KeyDown {'scancode': 33, 'key': 102, 'unicode': u'f', 'mod': 4096})>
- infor: 244
- time: 1374995058.62
- <Event(3-KeyUp {'scancode': 32, 'key': 100, 'mod': 4096})>
- infor: 248
- time: 1374995058.86
- <Event(2-KeyDown {'scancode': 34, 'key': 103, 'unicode': u'g', 'mod': 4096})>
- infor: 245
- time: 1374995059.11
- <Event(3-KeyUp {'scancode': 33, 'key': 102, 'mod': 4096})>
- infor: 240
- time: 1374995059.35
- <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (208, 91), 'rel': (3, -1)})>
- infor: 245
- time: 1374995059.59
- <Event(2-KeyDown {'scancode': 35, 'key': 104, 'unicode': u'h', 'mod': 4096})>
- infor: 242
- time: 1374995059.83
- <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (213, 90), 'rel': (5, -1)})>
- infor: 242
- time: 1374995060.08
- <Event(3-KeyUp {'scancode': 34, 'key': 103, 'mod': 4096})>
- infor: 247
- time: 1374995060.33
- <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (216, 90), 'rel': (3, 0)})>
- infor: 245
- time: 1374995060.57
- <Event(2-KeyDown {'scancode': 36, 'key': 106, 'unicode': u'j', 'mod': 4096})>
- infor: 247
- time: 1374995060.82
- <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (221, 89), 'rel': (5, -1)})>
- infor: 241
- time: 1374995061.06
- <Event(3-KeyUp {'scancode': 35, 'key': 104, 'mod': 4096})>
- infor: 249
- time: 1374995061.31
- <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (223, 89), 'rel': (2, 0)})>
- infor: 247
- time: 1374995061.56
- <Event(2-KeyDown {'scancode': 37, 'key': 107, 'unicode': u'k', 'mod': 4096})>
- infor: 255
- time: 1374995061.81
- <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (225, 89), 'rel': (2, 0)})>
- infor: 246
- time: 1374995062.06
- <Event(3-KeyUp {'scancode': 36, 'key': 106, 'mod': 4096})>
- infor: 245
- time: 1374995062.3
- <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (229, 88), 'rel': (4, -1)})>
- infor: 247
- time: 1374995062.55
- <Event(2-KeyDown {'scancode': 38, 'key': 108, 'unicode': u'l', 'mod': 4096})>
- infor: 242
- time: 1374995062.79
- <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (230, 88), 'rel': (1, 0)})>
- infor: 249
- time: 1374995063.04
- <Event(3-KeyUp {'scancode': 37, 'key': 107, 'mod': 4096})>
- infor: 249
- time: 1374995063.29
- <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (232, 88), 'rel': (2, 0)})>
- infor: 250
- time: 1374995063.54
- <Event(3-KeyUp {'scancode': 38, 'key': 108, 'mod': 4096})>
- infor: 243
- time: 1374995063.78
- <Event(1-ActiveEvent {'state': 1, 'gain': 0})>
- ************************************
- 94
- out: 23097
- outtime: 1374995064.05
- ************************************
- 0
- out: 48
- outtime: 1374995064.09
- ************************************
- 0
- out: 37
- outtime: 1374995064.12
- ************************************
- 0
- out: 32
- outtime: 1374995064.16
- ************************************
- 0
- out: 36
- outtime: 1374995064.19
- ************************************
- 0
- out: 32
- outtime: 1374995064.22
- ************************************
- 0
- out: 32
- outtime: 1374995064.26
- ************************************
- 0
- out: 34
- outtime: 1374995064.29
- ************************************
- 0
- out: 32
- outtime: 1374995064.32
- ************************************
- 0
- out: 32
- outtime: 1374995064.35
- ************************************
- 0
- out: 34
- outtime: 1374995064.39
- ************************************
- 0
- out: 34
- outtime: 1374995064.42
- ************************************
- 0
- out: 33
- outtime: 1374995064.45
- ************************************
- 0
- out: 34
- outtime: 1374995064.49
- ************************************
- 0
- out: 33
- outtime: 1374995064.52
- ************************************
- 0
- out: 35
- outtime: 1374995064.56
- ************************************
- 0
- out: 35
- outtime: 1374995064.59
- ************************************
- 0
- out: 33
- outtime: 1374995064.62
- ************************************
- 0
- out: 34
- outtime: 1374995064.66
- ************************************
- 0
- out: 36
- outtime: 1374995064.69
- ************************************
- 0
- out: 35
- outtime: 1374995064.73
- ************************************
- 0
- out: 34
- outtime: 1374995064.76
- ************************************
- 0
- out: 35
- outtime: 1374995064.8
- ************************************
- 0
- out: 31
- outtime: 1374995064.83
- ************************************
- 0
- out: 33
- outtime: 1374995064.86
- ************************************
- 0
- out: 38
- outtime: 1374995064.9
- ************************************
- 0
- out: 42
- outtime: 1374995064.94
- ************************************
- 0
- out: 37
- outtime: 1374995064.98
- ************************************
- 0
- out: 32
- outtime: 1374995065.01
- ************************************
- 0
- out: 34
- outtime: 1374995065.05
- ************************************
- 0
- out: 36
- outtime: 1374995065.08
- ************************************
- 0
- out: 34
- outtime: 1374995065.12
- ************************************
- 0
- out: 31
- outtime: 1374995065.15
- ************************************
- 0
- out: 37
- outtime: 1374995065.18
- ************************************
- 0
- out: 32
- outtime: 1374995065.21
- ************************************
- 0
- out: 33
- outtime: 1374995065.25
- ************************************
- 0
- out: 33
- outtime: 1374995065.28
- ************************************
- 0
- out: 32
- outtime: 1374995065.31
- ************************************
- 0
- out: 34
- outtime: 1374995065.35
- ************************************
- 0
- out: 34
- outtime: 1374995065.38
- >>>
总之,大概就是这个意思
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。