我還是個新來的python,並且已經開始使用pygame。我正在製作一個無盡的亞軍遊戲,但是我的跑步週期遇到了問題。這裏是我的代碼:基本運行週期不工作
import pygame
import sys
from pygame.locals import *
pygame.init()
clock = pygame.time.Clock()
clock2 = pygame.time.get_ticks()
screen = pygame.display.set_mode((640, 575))
bgx = 0
bgx2 = -800
scroll = 10
pose = 1
background = pygame.image.load("images/background2.png").convert_alpha();
player = pygame.image.load("images/character1.png").convert_alpha();
screen.blit(background, (0, 0))
def draw_screen(x):
screen.blit(background, (x, 0))
def draw_screen2(x2):
screen.blit(background, (x2, 0))
def draw_player(pose):
if pose == 1:
player = pygame.image.load("images/character1.png").convert_alpha();
screen.blit(player, (0, 0))
elif pose == 2:
player = pygame.image.load("images/character2.png").convert_alpha();
screen.blit(player, (0, 0))
elif pose == 3:
player = pygame.image.load("images/character3.png").convert_alpha();
screen.blit(player, (0, 0))
elif pose == 4:
player = pygame.image.load("images/character2.png").convert_alpha();
screen.blit(player, (0, 0))
def set_poses(pose):
if pose == 1:
pose = 2
if pose == 2:
pose = 3
if pose == 3:
pose = 4
if pose == 4:
pose = 1
while True: #Loop
clock2 = pygame.time.get_ticks()
#Quitting Function
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
quit()
clock.tick(50)
#Screen Scrolling
if bgx != 800:
bgx += scroll
else:
bgx = 0
if bgx2 != 0:
bgx2 += scroll
else:
bgx2 = -800
#Drawing Items
draw_screen2(bgx2)
draw_screen(bgx)
draw_player(pose)
if clock2%6 == 0:
set_poses(pose)
pygame.display.update()
所以屏幕滾動,並出現在我的性格,但他留在他的第一個位置(幀我猜。)在部分地方運行set_poses(pose)
我試圖擁有它也是對之前打印的東西設置它的姿勢,但沒有設置姿勢。我試着讓它打印出姿勢,並表明姿勢沒有變化。所以,是的,我發現了我的問題,但我不能爲我的生活尋找解決方案。
Btw。詳細瞭解[MCVE],_not設置pose_可以在沒有pygame和所有代碼邏輯的情況下進行復制。 –