如何解决它说“pxc”未定义
CS
import pygame
# itilaze
pygame.init()
# title and icon
icon = pygame.image.load("satanic.png")
pygame.display.set_caption("demo")
pygame.display.set_icon(icon)
playerImg = pygame.image.load("pixil-frame-0 (1).png")
Px = 370
Py = 480
def player(x,y):
screen.blit(playerImg,(x,y))
# ekran boyutu
screen = pygame.display.set_mode((800,600))
# LOOP
running = True
while running:
screen.fill((50,3,10)) # rgb
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
Pxc = -0.5
if event.key == pygame.K_RIGHT:
Pxc = 0.5
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
Pxc = 0
Px += Pxc
player(Px,Py) # adam
pygame.display.update()
如果你们能帮助我就好了 我今天开始学习 phyton
解决方法
Pxy
仅在事件循环中设置。因此,如果没有事件发生,则永远不会设置 Pxc
。在应用程序循环之前初始化 Pxc
:
Pxc = 0 # <--- ADD THIS
running = True
while running:
# [...]
Px += Pxc
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。