我创建了这个来移动精灵。我在不同的文件中将精灵图像坐标设置为(精灵,300)。运行程序并按左右箭头,没有任何动作。spritex 的值在打印函数中发生变化
我通过添加打印功能检查了程序是否正在读取按键。我是否设置了错误的程序?
------运动功能文件
import pygame
import os, sys
from itertools import *
from oryxsprites import *
from oryxdisplay import *
spritex = 300
screen = pygame.display.set_mode((640, 640))
def movementsprite():
global spritex
keys = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if keys[pygame.K_RIGHT]:
spritex += 10
print spritex
elif keys[pygame.K_LEFT]:
spritex -= 10
print spritex
------显示函数文件---------------
import pygame
import itertools
from oryxsprites import *
from McharMovement import *
screen = pygame.display.set_mode((640, 640))
spritex = 300
def backgroundmain():
movementsprite()
backdrop = pygame.Rect(0, 0, 640, 640)
screen.fill((50,50,50))
playingfeildwidth = (32, 608)
playingfeildheight = (32, 608)
screen.blit(warrior1, (spritex, 320))
pygame.display.flip()
-----主文件------
import pygame
import os, sys
from itertools import *
from oryxsprites import *
from oryxdisplay import *
from McharMovement import *
running = True
while running:
backgroundmain()
pygame.display.set_caption('OryxGame')
pygame.display.set_icon(grasstile)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()