当前位置:   article > 正文

pygame.event.get()

pygame.event.get()

刚学习python+pygame就遇到了个棘手的问题——pygame.event.get()

这是官方注释

pygame.event. get ( )
get events from the queue
get() -> Eventlist
get(type) -> Eventlist
get(typelist) -> Eventlist

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.

写进代码里思路就乱了,比如这个例子

  1. background_image_filename = 'sushiplate.jpg'
  2. import pygame
  3. from pygame.locals import *
  4. from sys import exit
  5. pygame.init()
  6. screen = pygame.display.set_mode((640, 480), 0, 32)
  7. background = pygame.image.load(background_image_filename).convert()
  8. x, y = 0, 0
  9. move_x, move_y = 0, 0
  10. while True:
  11. for event in pygame.event.get():
  12. if event.type == QUIT:
  13. exit()
  14. if event.type == KEYDOWN:
  15. #键盘有按下?
  16. if event.key == K_LEFT:
  17. #按下的是左方向键的话,把x坐标减一
  18. move_x = -1
  19. elif event.key == K_RIGHT:
  20. #右方向键则加一
  21. move_x = 1
  22. elif event.key == K_UP:
  23. #类似了
  24. move_y = -1
  25. elif event.key == K_DOWN:
  26. move_y = 1
  27. elif event.type == KEYUP:
  28. #如果用户放开了键盘,图就不要动了
  29. move_x = 0
  30. move_y = 0
  31. #计算出新的坐标
  32. x+= move_x
  33. y+= move_y
  34. screen.fill((0,0,0))
  35. screen.blit(background, (x,y))
  36. #在新的位置上画图
  37. pygame.display.update()

自己又写了个模拟帮助理解

  1. import pygame,time
  2. pygame.init()
  3. screen = pygame.display.set_mode((640, 480), 0, 32)
  4. pygame.display.update()
  5. clock=pygame.time.Clock()
  6. outclock=pygame.time.Clock()
  7. while True:
  8. tt=0
  9. for event in pygame.event.get():
  10. if event.type == pygame.QUIT:
  11. exit()
  12. print 'infor: ',clock.tick()
  13. print 'time: ',time.time()
  14. print str(event)
  15. tt+=1
  16. pygame.time.delay(200)
  17. print '************************************'
  18. print tt
  19. print 'out: ',outclock.tick()
  20. print 'outtime: ',time.time()
在键盘上乱按一通,输出是介个样子

  1. Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32
  2. Type "copyright", "credits" or "license()" for more information.
  3. >>> ================================ RESTART ================================
  4. >>>
  5. infor: 7
  6. time: 1374995035.72
  7. <Event(17-VideoExpose {})>
  8. infor: 239
  9. time: 1374995035.96
  10. <Event(1-ActiveEvent {'state': 1, 'gain': 0})>
  11. ************************************
  12. 2
  13. out: 491
  14. outtime: 1374995036.2
  15. infor: 261
  16. time: 1374995036.21
  17. <Event(1-ActiveEvent {'state': 1, 'gain': 1})>
  18. infor: 239
  19. time: 1374995036.46
  20. <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (203, 96), 'rel': (203, 96)})>
  21. ************************************
  22. 2
  23. out: 504
  24. outtime: 1374995036.71
  25. infor: 263
  26. time: 1374995036.73
  27. <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (202, 99), 'rel': (-1, 3)})>
  28. infor: 246
  29. time: 1374995036.97
  30. <Event(2-KeyDown {'scancode': 32, 'key': 100, 'unicode': u'd', 'mod': 4096})>
  31. ************************************
  32. 2
  33. out: 504
  34. outtime: 1374995037.21
  35. infor: 260
  36. time: 1374995037.23
  37. <Event(2-KeyDown {'scancode': 33, 'key': 102, 'unicode': u'f', 'mod': 4096})>
  38. infor: 235
  39. time: 1374995037.47
  40. <Event(3-KeyUp {'scancode': 32, 'key': 100, 'mod': 4096})>
  41. infor: 251
  42. time: 1374995037.71
  43. <Event(2-KeyDown {'scancode': 34, 'key': 103, 'unicode': u'g', 'mod': 4096})>
  44. infor: 248
  45. time: 1374995037.96
  46. <Event(3-KeyUp {'scancode': 33, 'key': 102, 'mod': 4096})>
  47. infor: 249
  48. time: 1374995038.21
  49. <Event(2-KeyDown {'scancode': 35, 'key': 104, 'unicode': u'h', 'mod': 4096})>
  50. infor: 242
  51. time: 1374995038.46
  52. <Event(2-KeyDown {'scancode': 20, 'key': 116, 'unicode': u't', 'mod': 4096})>
  53. infor: 256
  54. time: 1374995038.71
  55. <Event(3-KeyUp {'scancode': 34, 'key': 103, 'mod': 4096})>
  56. infor: 250
  57. time: 1374995038.96
  58. <Event(3-KeyUp {'scancode': 20, 'key': 116, 'mod': 4096})>
  59. infor: 243
  60. time: 1374995039.2
  61. <Event(2-KeyDown {'scancode': 21, 'key': 121, 'unicode': u'y', 'mod': 4096})>
  62. infor: 248
  63. time: 1374995039.45
  64. <Event(2-KeyDown {'scancode': 36, 'key': 106, 'unicode': u'j', 'mod': 4096})>
  65. infor: 242
  66. time: 1374995039.69
  67. <Event(3-KeyUp {'scancode': 35, 'key': 104, 'mod': 4096})>
  68. infor: 245
  69. time: 1374995039.94
  70. <Event(3-KeyUp {'scancode': 21, 'key': 121, 'mod': 4096})>
  71. infor: 251
  72. time: 1374995040.19
  73. <Event(2-KeyDown {'scancode': 37, 'key': 107, 'unicode': u'k', 'mod': 4096})>
  74. infor: 242
  75. time: 1374995040.43
  76. <Event(2-KeyDown {'scancode': 22, 'key': 117, 'unicode': u'u', 'mod': 4096})>
  77. infor: 250
  78. time: 1374995040.68
  79. <Event(3-KeyUp {'scancode': 36, 'key': 106, 'mod': 4096})>
  80. ************************************
  81. 15
  82. out: 3728
  83. outtime: 1374995040.94
  84. infor: 286
  85. time: 1374995040.97
  86. <Event(3-KeyUp {'scancode': 22, 'key': 117, 'mod': 4096})>
  87. infor: 249
  88. time: 1374995041.22
  89. <Event(2-KeyDown {'scancode': 38, 'key': 108, 'unicode': u'l', 'mod': 4096})>
  90. infor: 244
  91. time: 1374995041.46
  92. <Event(3-KeyUp {'scancode': 37, 'key': 107, 'mod': 4096})>
  93. infor: 249
  94. time: 1374995041.71
  95. <Event(2-KeyDown {'scancode': 39, 'key': 59, 'unicode': u';', 'mod': 4096})>
  96. infor: 243
  97. time: 1374995041.95
  98. <Event(2-KeyDown {'scancode': 24, 'key': 111, 'unicode': u'o', 'mod': 4096})>
  99. infor: 242
  100. time: 1374995042.19
  101. <Event(3-KeyUp {'scancode': 39, 'key': 59, 'mod': 4096})>
  102. infor: 247
  103. time: 1374995042.44
  104. <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (202, 98), 'rel': (0, -1)})>
  105. infor: 247
  106. time: 1374995042.69
  107. <Event(3-KeyUp {'scancode': 24, 'key': 111, 'mod': 4096})>
  108. infor: 245
  109. time: 1374995042.93
  110. <Event(2-KeyDown {'scancode': 37, 'key': 107, 'unicode': u'k', 'mod': 4096})>
  111. infor: 242
  112. time: 1374995043.18
  113. <Event(3-KeyUp {'scancode': 38, 'key': 108, 'mod': 4096})>
  114. infor: 250
  115. time: 1374995043.42
  116. <Event(2-KeyDown {'scancode': 36, 'key': 106, 'unicode': u'j', 'mod': 4096})>
  117. infor: 242
  118. time: 1374995043.67
  119. <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (202, 97), 'rel': (0, -1)})>
  120. infor: 251
  121. time: 1374995043.92
  122. <Event(3-KeyUp {'scancode': 37, 'key': 107, 'mod': 4096})>
  123. infor: 247
  124. time: 1374995044.16
  125. <Event(2-KeyDown {'scancode': 35, 'key': 104, 'unicode': u'h', 'mod': 4096})>
  126. infor: 242
  127. time: 1374995044.4
  128. <Event(3-KeyUp {'scancode': 36, 'key': 106, 'mod': 4096})>
  129. infor: 247
  130. time: 1374995044.65
  131. <Event(2-KeyDown {'scancode': 34, 'key': 103, 'unicode': u'g', 'mod': 4096})>
  132. infor: 244
  133. time: 1374995044.9
  134. <Event(3-KeyUp {'scancode': 35, 'key': 104, 'mod': 4096})>
  135. infor: 249
  136. time: 1374995045.15
  137. <Event(2-KeyDown {'scancode': 33, 'key': 102, 'unicode': u'f', 'mod': 4096})>
  138. infor: 246
  139. time: 1374995045.39
  140. <Event(3-KeyUp {'scancode': 34, 'key': 103, 'mod': 4096})>
  141. infor: 251
  142. time: 1374995045.64
  143. <Event(2-KeyDown {'scancode': 32, 'key': 100, 'unicode': u'd', 'mod': 4096})>
  144. infor: 246
  145. time: 1374995045.89
  146. <Event(3-KeyUp {'scancode': 33, 'key': 102, 'mod': 4096})>
  147. infor: 251
  148. time: 1374995046.14
  149. <Event(2-KeyDown {'scancode': 31, 'key': 115, 'unicode': u's', 'mod': 4096})>
  150. infor: 241
  151. time: 1374995046.38
  152. <Event(3-KeyUp {'scancode': 32, 'key': 100, 'mod': 4096})>
  153. infor: 246
  154. time: 1374995046.62
  155. <Event(2-KeyDown {'scancode': 30, 'key': 97, 'unicode': u'a', 'mod': 4096})>
  156. infor: 240
  157. time: 1374995046.87
  158. <Event(3-KeyUp {'scancode': 31, 'key': 115, 'mod': 4096})>
  159. infor: 249
  160. time: 1374995047.12
  161. <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (202, 95), 'rel': (0, -2)})>
  162. infor: 251
  163. time: 1374995047.37
  164. <Event(2-KeyDown {'scancode': 31, 'key': 115, 'unicode': u's', 'mod': 4096})>
  165. infor: 244
  166. time: 1374995047.61
  167. <Event(3-KeyUp {'scancode': 30, 'key': 97, 'mod': 4096})>
  168. infor: 242
  169. time: 1374995047.85
  170. <Event(2-KeyDown {'scancode': 32, 'key': 100, 'unicode': u'd', 'mod': 4096})>
  171. infor: 241
  172. time: 1374995048.09
  173. <Event(3-KeyUp {'scancode': 31, 'key': 115, 'mod': 4096})>
  174. infor: 243
  175. time: 1374995048.34
  176. <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (203, 94), 'rel': (1, -1)})>
  177. infor: 242
  178. time: 1374995048.58
  179. <Event(2-KeyDown {'scancode': 33, 'key': 102, 'unicode': u'f', 'mod': 4096})>
  180. infor: 249
  181. time: 1374995048.83
  182. <Event(3-KeyUp {'scancode': 32, 'key': 100, 'mod': 4096})>
  183. infor: 246
  184. time: 1374995049.07
  185. <Event(2-KeyDown {'scancode': 34, 'key': 103, 'unicode': u'g', 'mod': 4096})>
  186. infor: 250
  187. time: 1374995049.32
  188. <Event(3-KeyUp {'scancode': 33, 'key': 102, 'mod': 4096})>
  189. infor: 244
  190. time: 1374995049.57
  191. <Event(2-KeyDown {'scancode': 35, 'key': 104, 'unicode': u'h', 'mod': 4096})>
  192. infor: 241
  193. time: 1374995049.81
  194. <Event(2-KeyDown {'scancode': 49, 'key': 110, 'unicode': u'n', 'mod': 4096})>
  195. infor: 242
  196. time: 1374995050.05
  197. <Event(3-KeyUp {'scancode': 34, 'key': 103, 'mod': 4096})>
  198. infor: 242
  199. time: 1374995050.29
  200. <Event(2-KeyDown {'scancode': 50, 'key': 109, 'unicode': u'm', 'mod': 4096})>
  201. infor: 242
  202. time: 1374995050.54
  203. <Event(3-KeyUp {'scancode': 49, 'key': 110, 'mod': 4096})>
  204. infor: 249
  205. time: 1374995050.79
  206. <Event(2-KeyDown {'scancode': 36, 'key': 106, 'unicode': u'j', 'mod': 4096})>
  207. infor: 243
  208. time: 1374995051.03
  209. <Event(3-KeyUp {'scancode': 35, 'key': 104, 'mod': 4096})>
  210. infor: 247
  211. time: 1374995051.28
  212. <Event(2-KeyDown {'scancode': 51, 'key': 44, 'unicode': u',', 'mod': 4096})>
  213. infor: 243
  214. time: 1374995051.52
  215. <Event(3-KeyUp {'scancode': 36, 'key': 106, 'mod': 4096})>
  216. infor: 242
  217. time: 1374995051.76
  218. <Event(3-KeyUp {'scancode': 50, 'key': 109, 'mod': 4096})>
  219. infor: 247
  220. time: 1374995052.01
  221. <Event(2-KeyDown {'scancode': 37, 'key': 107, 'unicode': u'k', 'mod': 4096})>
  222. infor: 243
  223. time: 1374995052.25
  224. <Event(3-KeyUp {'scancode': 51, 'key': 44, 'mod': 4096})>
  225. infor: 248
  226. time: 1374995052.5
  227. <Event(3-KeyUp {'scancode': 37, 'key': 107, 'mod': 4096})>
  228. infor: 242
  229. time: 1374995052.74
  230. <Event(2-KeyDown {'scancode': 38, 'key': 108, 'unicode': u'l', 'mod': 4096})>
  231. infor: 249
  232. time: 1374995052.99
  233. <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (204, 94), 'rel': (1, 0)})>
  234. infor: 241
  235. time: 1374995053.23
  236. <Event(2-KeyDown {'scancode': 37, 'key': 107, 'unicode': u'k', 'mod': 4096})>
  237. infor: 242
  238. time: 1374995053.47
  239. <Event(3-KeyUp {'scancode': 38, 'key': 108, 'mod': 4096})>
  240. infor: 246
  241. time: 1374995053.71
  242. <Event(2-KeyDown {'scancode': 36, 'key': 106, 'unicode': u'j', 'mod': 4096})>
  243. infor: 243
  244. time: 1374995053.96
  245. <Event(2-KeyDown {'scancode': 35, 'key': 104, 'unicode': u'h', 'mod': 4096})>
  246. infor: 247
  247. time: 1374995054.21
  248. <Event(3-KeyUp {'scancode': 37, 'key': 107, 'mod': 4096})>
  249. infor: 245
  250. time: 1374995054.45
  251. <Event(2-KeyDown {'scancode': 34, 'key': 103, 'unicode': u'g', 'mod': 4096})>
  252. infor: 248
  253. time: 1374995054.7
  254. <Event(3-KeyUp {'scancode': 36, 'key': 106, 'mod': 4096})>
  255. infor: 242
  256. time: 1374995054.94
  257. <Event(2-KeyDown {'scancode': 33, 'key': 102, 'unicode': u'f', 'mod': 4096})>
  258. infor: 252
  259. time: 1374995055.19
  260. <Event(3-KeyUp {'scancode': 35, 'key': 104, 'mod': 4096})>
  261. infor: 242
  262. time: 1374995055.44
  263. <Event(2-KeyDown {'scancode': 32, 'key': 100, 'unicode': u'd', 'mod': 4096})>
  264. infor: 253
  265. time: 1374995055.69
  266. <Event(3-KeyUp {'scancode': 34, 'key': 103, 'mod': 4096})>
  267. infor: 240
  268. time: 1374995055.93
  269. <Event(3-KeyUp {'scancode': 33, 'key': 102, 'mod': 4096})>
  270. infor: 244
  271. time: 1374995056.17
  272. <Event(2-KeyDown {'scancode': 31, 'key': 115, 'unicode': u's', 'mod': 4096})>
  273. infor: 246
  274. time: 1374995056.42
  275. <Event(3-KeyUp {'scancode': 32, 'key': 100, 'mod': 4096})>
  276. infor: 244
  277. time: 1374995056.67
  278. <Event(2-KeyDown {'scancode': 30, 'key': 97, 'unicode': u'a', 'mod': 4096})>
  279. infor: 250
  280. time: 1374995056.91
  281. <Event(3-KeyUp {'scancode': 31, 'key': 115, 'mod': 4096})>
  282. infor: 245
  283. time: 1374995057.16
  284. <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (205, 92), 'rel': (1, -2)})>
  285. infor: 242
  286. time: 1374995057.4
  287. <Event(2-KeyDown {'scancode': 31, 'key': 115, 'unicode': u's', 'mod': 4096})>
  288. infor: 241
  289. time: 1374995057.64
  290. <Event(3-KeyUp {'scancode': 30, 'key': 97, 'mod': 4096})>
  291. infor: 241
  292. time: 1374995057.88
  293. <Event(2-KeyDown {'scancode': 32, 'key': 100, 'unicode': u'd', 'mod': 4096})>
  294. infor: 243
  295. time: 1374995058.12
  296. <Event(3-KeyUp {'scancode': 31, 'key': 115, 'mod': 4096})>
  297. infor: 246
  298. time: 1374995058.37
  299. <Event(2-KeyDown {'scancode': 33, 'key': 102, 'unicode': u'f', 'mod': 4096})>
  300. infor: 244
  301. time: 1374995058.62
  302. <Event(3-KeyUp {'scancode': 32, 'key': 100, 'mod': 4096})>
  303. infor: 248
  304. time: 1374995058.86
  305. <Event(2-KeyDown {'scancode': 34, 'key': 103, 'unicode': u'g', 'mod': 4096})>
  306. infor: 245
  307. time: 1374995059.11
  308. <Event(3-KeyUp {'scancode': 33, 'key': 102, 'mod': 4096})>
  309. infor: 240
  310. time: 1374995059.35
  311. <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (208, 91), 'rel': (3, -1)})>
  312. infor: 245
  313. time: 1374995059.59
  314. <Event(2-KeyDown {'scancode': 35, 'key': 104, 'unicode': u'h', 'mod': 4096})>
  315. infor: 242
  316. time: 1374995059.83
  317. <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (213, 90), 'rel': (5, -1)})>
  318. infor: 242
  319. time: 1374995060.08
  320. <Event(3-KeyUp {'scancode': 34, 'key': 103, 'mod': 4096})>
  321. infor: 247
  322. time: 1374995060.33
  323. <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (216, 90), 'rel': (3, 0)})>
  324. infor: 245
  325. time: 1374995060.57
  326. <Event(2-KeyDown {'scancode': 36, 'key': 106, 'unicode': u'j', 'mod': 4096})>
  327. infor: 247
  328. time: 1374995060.82
  329. <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (221, 89), 'rel': (5, -1)})>
  330. infor: 241
  331. time: 1374995061.06
  332. <Event(3-KeyUp {'scancode': 35, 'key': 104, 'mod': 4096})>
  333. infor: 249
  334. time: 1374995061.31
  335. <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (223, 89), 'rel': (2, 0)})>
  336. infor: 247
  337. time: 1374995061.56
  338. <Event(2-KeyDown {'scancode': 37, 'key': 107, 'unicode': u'k', 'mod': 4096})>
  339. infor: 255
  340. time: 1374995061.81
  341. <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (225, 89), 'rel': (2, 0)})>
  342. infor: 246
  343. time: 1374995062.06
  344. <Event(3-KeyUp {'scancode': 36, 'key': 106, 'mod': 4096})>
  345. infor: 245
  346. time: 1374995062.3
  347. <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (229, 88), 'rel': (4, -1)})>
  348. infor: 247
  349. time: 1374995062.55
  350. <Event(2-KeyDown {'scancode': 38, 'key': 108, 'unicode': u'l', 'mod': 4096})>
  351. infor: 242
  352. time: 1374995062.79
  353. <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (230, 88), 'rel': (1, 0)})>
  354. infor: 249
  355. time: 1374995063.04
  356. <Event(3-KeyUp {'scancode': 37, 'key': 107, 'mod': 4096})>
  357. infor: 249
  358. time: 1374995063.29
  359. <Event(4-MouseMotion {'buttons': (0, 0, 0), 'pos': (232, 88), 'rel': (2, 0)})>
  360. infor: 250
  361. time: 1374995063.54
  362. <Event(3-KeyUp {'scancode': 38, 'key': 108, 'mod': 4096})>
  363. infor: 243
  364. time: 1374995063.78
  365. <Event(1-ActiveEvent {'state': 1, 'gain': 0})>
  366. ************************************
  367. 94
  368. out: 23097
  369. outtime: 1374995064.05
  370. ************************************
  371. 0
  372. out: 48
  373. outtime: 1374995064.09
  374. ************************************
  375. 0
  376. out: 37
  377. outtime: 1374995064.12
  378. ************************************
  379. 0
  380. out: 32
  381. outtime: 1374995064.16
  382. ************************************
  383. 0
  384. out: 36
  385. outtime: 1374995064.19
  386. ************************************
  387. 0
  388. out: 32
  389. outtime: 1374995064.22
  390. ************************************
  391. 0
  392. out: 32
  393. outtime: 1374995064.26
  394. ************************************
  395. 0
  396. out: 34
  397. outtime: 1374995064.29
  398. ************************************
  399. 0
  400. out: 32
  401. outtime: 1374995064.32
  402. ************************************
  403. 0
  404. out: 32
  405. outtime: 1374995064.35
  406. ************************************
  407. 0
  408. out: 34
  409. outtime: 1374995064.39
  410. ************************************
  411. 0
  412. out: 34
  413. outtime: 1374995064.42
  414. ************************************
  415. 0
  416. out: 33
  417. outtime: 1374995064.45
  418. ************************************
  419. 0
  420. out: 34
  421. outtime: 1374995064.49
  422. ************************************
  423. 0
  424. out: 33
  425. outtime: 1374995064.52
  426. ************************************
  427. 0
  428. out: 35
  429. outtime: 1374995064.56
  430. ************************************
  431. 0
  432. out: 35
  433. outtime: 1374995064.59
  434. ************************************
  435. 0
  436. out: 33
  437. outtime: 1374995064.62
  438. ************************************
  439. 0
  440. out: 34
  441. outtime: 1374995064.66
  442. ************************************
  443. 0
  444. out: 36
  445. outtime: 1374995064.69
  446. ************************************
  447. 0
  448. out: 35
  449. outtime: 1374995064.73
  450. ************************************
  451. 0
  452. out: 34
  453. outtime: 1374995064.76
  454. ************************************
  455. 0
  456. out: 35
  457. outtime: 1374995064.8
  458. ************************************
  459. 0
  460. out: 31
  461. outtime: 1374995064.83
  462. ************************************
  463. 0
  464. out: 33
  465. outtime: 1374995064.86
  466. ************************************
  467. 0
  468. out: 38
  469. outtime: 1374995064.9
  470. ************************************
  471. 0
  472. out: 42
  473. outtime: 1374995064.94
  474. ************************************
  475. 0
  476. out: 37
  477. outtime: 1374995064.98
  478. ************************************
  479. 0
  480. out: 32
  481. outtime: 1374995065.01
  482. ************************************
  483. 0
  484. out: 34
  485. outtime: 1374995065.05
  486. ************************************
  487. 0
  488. out: 36
  489. outtime: 1374995065.08
  490. ************************************
  491. 0
  492. out: 34
  493. outtime: 1374995065.12
  494. ************************************
  495. 0
  496. out: 31
  497. outtime: 1374995065.15
  498. ************************************
  499. 0
  500. out: 37
  501. outtime: 1374995065.18
  502. ************************************
  503. 0
  504. out: 32
  505. outtime: 1374995065.21
  506. ************************************
  507. 0
  508. out: 33
  509. outtime: 1374995065.25
  510. ************************************
  511. 0
  512. out: 33
  513. outtime: 1374995065.28
  514. ************************************
  515. 0
  516. out: 32
  517. outtime: 1374995065.31
  518. ************************************
  519. 0
  520. out: 34
  521. outtime: 1374995065.35
  522. ************************************
  523. 0
  524. out: 34
  525. outtime: 1374995065.38
  526. >>>

观察发现,pygame.event.get()取走外部输入信息队列的时候是有个时间间隔的,这个间隔和程序本身运行的速度有关系,这里可以通过修改pygame.time.delay()里的值发现。之所以在for in pygame.event.get()循环里加入pygame.time.delay()这一句是因为程序跑的要比你手指输入快得多,现在有了pygame.time.delay()这个神器咱终于可以比程序跑得更快了,只要你以一定的速度输入下去,外部输入信息队列会因为pygame.event.get()不能及时取走而装的很多,当pygame.event.get()终于处理完曾经取走的信息,等待它的又是外部输入信息队列里好大一坨的外部输入信息··· ···

总之,大概就是这个意思


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/984645
推荐阅读
相关标签
  

闽ICP备14008679号