|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
pygame的课后作业我在做的时候
遇到了一些问题
这是代码:- import pygame
- pygame.init()
- x = 50
- sc = pygame.display.set_mode((500, 500))
- sc.fill((0, 0, 100))
- pygame.display.update()
- pygame.draw.circle(sc, (255, 0, 0), (250, 250), x)
- pygame.display.update()
- pygame.key.set_repeat(500, 500)
- while True:
- pygame.draw.circle(sc, (255, 0, 0), (250, 250), x)
- pygame.display.update()
- print(x)
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- exit()
- if event.type == pygame.KEYDOWN:
-
- if event.key == pygame.K_DOWN:
- if x > 0:
- x -= 5
- elif event.key == pygame.K_UP:
- if x < 250:
- x += 5
复制代码
问题是 我在K_UP的判断的时候
都可以让这个元变大
但是K_DOWN的时候
就不可以
有人知道是怎么回事吗
本帖最后由 wuqramy 于 2020-6-14 14:13 编辑
不要紧用update
擅用Clock 在这之前还要pygame.display.flip()
参考文章: https://www.runoob.com/python/att-time-clock.html
可以多了解这方面的内容
- import pygame
- pygame.init()
- x = 50
- sc = pygame.display.set_mode((500, 500))
- pygame.display.set_caption('drawing')
- clock = pygame.time.Clock()
- while True:
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- pygame.quit()
- exit()
- elif event.type == pygame.KEYDOWN:
- if event.key == pygame.K_DOWN:
- if x > 0:
- x -= 5
- elif event.key == pygame.K_UP:
- if x < 250:
- x += 5
- sc.fill((0, 0, 100))
- pygame.draw.circle(sc, (255, 0, 0), (250, 250), x)
- pygame.display.flip()
- clock.tick(120)
复制代码
|
|