【问题标题】:pygame, right goes downpygame,权利下降
【发布时间】:2015-11-02 01:55:03
【问题描述】:

我在 pygame 上使用 2.7.10,但我不明白为什么权利一直下降而不是权利下降。左边完美。我找不到任何相关的问题,所以有人知道这有什么问题吗?

import pygame

pygame.init()

GameDisplay = pygame.display.set_mode((800, 600))

White = (255,255,255)
Black = (0,0,0)
Red = (255,0,0)

pygame.display.set_caption('Test')

PyQuit = False

lead_x = 300
lead_y = 300

while not PyQuit:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            PyQuit = True
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                lead_x -= 10
            if event.key == pygame.K_RIGHT:
                lead_y += 10


    GameDisplay.fill(White)
    pygame.draw.rect(GameDisplay, Black, [lead_x,lead_y,10,10])
    pygame.display.update()

pygame.quit()
quit()

【问题讨论】:

    标签: python python-2.7 pygame


    【解决方案1】:

    代替:

    lead_y += 10
    

    试试:

    lead_x += 10
    

    使用lead_x 表示水平,lead_y 表示垂直。

    【讨论】:

    • 谢谢!现在我懂了! =]
    【解决方案2】:
    if event.key == pygame.K_RIGHT:
                    lead_y += 10'
    

    当你应该在 x 坐标上加 10 时,你正在使 lead_y += 10

    if event.key == pygame.K_RIGHT:
                        lead_x += 10'
    

    【讨论】:

    • 感谢您的帮助!
    猜你喜欢
    • 2016-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-27
    • 1970-01-01
    相关资源
    最近更新 更多