2014-01-15 126 views
1

我正在pygame上做遊戲,當我去運行遊戲時什麼都沒有發生。一個黑盒子出現,但什麼都不做,沒有顯示器等。另外,我錯誤的是Python Shell沒有顯示任何錯誤。這裏是主文件的代碼:PyGame:什麼都沒發生

import pygame 
import sys 
import random 
import pygame.mixer 
import math 
from constants import * 
from player import * 

class Game(): 

    def __init__(self): 

     #States (Not country states) 
     self.game_state = STATE_INGAME 

     #State variables 
     #self.stateMenu = 

     #Screen 
     size = SCREEN_WIDTH, SCREEN_HEIGHT 
     self.screen = pygame.display.set_mode(size) 
     pygame.display.set_caption('WIP') 
     self.screen_rect = self.screen.get_rect() 

     # Player 
     self.player = Player(SCREEN_WIDTH/2, SCREEN_HEIGHT/2) 

    def run(self): 

     clock = pygame.time.Clock() 

     if self.game_state == STATE_INGAME: 

      for event in pygame.event.get(): 
       if event.type == pygame.QUIT: 
        pygame.quit() 
        sys.exit() 

      self.player_move() 
      self.player.update() 
      self.player.render(self.screen) 

     clock.tick(100) 

    def player_move(self): 

     # move player and check for collision at the same time 
     self.player.rect.x += self.player.velX 
     self.player.rect.y += self.player.velY 

Game().run() 

我已經檢查了球員的文件很多次,也有在那裏完全沒有錯誤。那麼不是我所能看到的。謝謝您的幫助!

回答

0

你需要一個while-loop

def run(self): 

    clock = pygame.time.Clock() 
    while True: 
     if self.game_state == STATE_INGAME: 
      for event in pygame.event.get(): 
       if event.type == pygame.QUIT: 
        pygame.quit() 
        sys.exit() 
      self.player_move() 
      self.player.update() 
      self.player.render(self.screen) 

     clock.tick(100) 
+0

該死。沒有看到。感謝您指出這一點。有時候我忘記了要添加的部分:/ – GhostFrag1

+0

再次感謝您的回答。但是我遇到的另一個問題是我的播放器沒有移動:(它會顯示,但是不會移動,我可以在私密聊天中提供代碼供您查看,再次感謝您。 – GhostFrag1

+0

請在此處發佈您的代碼 – unutbu

相關問題