【问题标题】:Use capital letters as input for pygame controls使用大写字母作为 pygame 控件的输入
【发布时间】:2013-11-08 23:19:40
【问题描述】:

我对围绕 x 轴的 pygame 绘图旋转有以下关键设置:

while done == False:
# ALL EVENT PROCESSING SHOULD GO BELOW THIS COMMENT
for event in pygame.event.get(): # User did something
    if event.type == pygame.QUIT: # If user clicked close
         done = True # Flag that we are done so we exit this loop
        # User pressed down on a key
keys = pygame.key.get_pressed()

 #X rotation clockwise
 if keys[pygame.K_x]:
 #rotate around the x axis
    angle_y = angle_y+.1

 if pygame.key.get_mods() & pygame.KMOD_LSHIFT:
    #X rotation counterclockwise
    if key[pygame.K_x]:
      angle_y = angle_y+.1

我想按住 x 键,我的图像会绕 x 轴顺时针旋转 然后我想按住左移键和 x 键(或大写 X)并让图像逆时针旋转。

在我目前的设置下,即使我按住 shift,它也只会顺时针方向移动。

【问题讨论】:

  • 格式化您的代码 - 进行正确的缩进。

标签: rotation keyboard controls pygame keypress


【解决方案1】:

你在这两种情况下都有angle_y = angle_y+.1 - PLUS

(您的代码未格式化)

我认为您还需要将代码更改为:

if keys[pygame.K_x]:
   if pygame.key.get_mods() & pygame.KMOD_LSHIFT:
      #X rotation counterclockwise
      angle_y = angle_y-.1
   else:
      #X rotation clockwise
      angle_y = angle_y+.1

在你的版本中,如果你按left_shift + x 两个if 都是真的

if keys[pygame.K_x]: 为真

if pygame.key.get_mods() & pygame.KMOD_LSHIFT: if key[pygame.K_x]: 为真

【讨论】:

    猜你喜欢
    • 2011-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-11
    相关资源
    最近更新 更多