2016-08-22 32 views
0

我想做一個遊戲,現在我想顯示一個歡迎屏幕5秒。我輸入谷歌這個問題,並有很多結果,但沒有任何工作。我看到這個問題已經在堆棧溢出之前被覆蓋了,但是這對我不起作用。我試過time.sleep,pygame.time.set,pygame.time.tick等等。這是我現在的代碼,但之前我正在對其進行更改。這裏是代碼,並提前感謝。消息到屏幕將不會停止設定的時間後

#I imported all these mods just in case I need them, that way I don't have to worry about it 
import math 
import random 
import time 
import pygame 
import cx_Freeze 
import os 
import superwires 
import sys 
import pip 
import glob 
from pygame import * 
pygame.init() 
move=0 
FPS=60 
blue=(0,0,255) 
white=(255,255,255) 
black=(0,0,0) 
green=(0,155,0) 
display_width=800 
display_height=600 
gamedisplay=pygame.display.set_mode((display_width,display_height)) 
pygame.display.set_caption('Stacker') 
clock=pygame.time.Clock() 
smallfont=pygame.font.SysFont("Arial",25) 
mediumfont=pygame.font.SysFont("Arial",50) 
largefont=pygame.font.SysFont("Arial",80) 
gamedisplay.fill(green) 
pygame.display.update() 
def welcome_screen(): 
    welcome_message = largefont.render(str("Welcome to Stacker!!!"), True,black) 
    gamedisplay.blit(welcome_message,(87,25)) 
    pygame.display.update() 
play=True 
while play==True: 
    welcome_screen() 
    pygame.time.delay(5) 
    play=False 
    pygame.display.update() 
pygame.display.update() 
+0

當發佈代碼的嘗試,使[最小的完整工作示例(http://stackoverflow.com/help/mcve)尤其是你應該刪除任何導入你不需要。 –

回答

0

pygame.time.delay的參數是毫秒數。要暫停5秒pygame.time.delay(5000)

http://www.pygame.org/docs/ref/time.html#pygame.time.delay

我注意到,您導入pygame的第一兩倍import pygame,然後再爲from pygame import *這是不必要的。只導入你需要的模塊,只導入一次。

下面是一個小例子:

import pygame 
pygame.init() 

black=(0,0,0) 
green=(0,155,0) 
display_width=800 
display_height=600 
largefont=pygame.font.SysFont("Arial",80) 

gamedisplay=pygame.display.set_mode((display_width,display_height)) 
gamedisplay.fill(green) 

def welcome_screen(): 
    welcome_message = largefont.render(str("Welcome to Stacker!!!"), True,black) 
    gamedisplay.blit(welcome_message,(87,25)) 
    pygame.display.update() 

welcome_screen() 
pygame.time.delay(5000) 
+0

這還遠非最小的例子。白手起家。只包含您在示例中實際使用的模塊。不要在作業中使用你沒有使用的作業或定義。 「不起作用」不是對問題的描述。你期望它做什麼?當我運行你的代碼(延遲(5000))時,顯示「Welcome to Stacker」消息5秒鐘,程序退出。這不是你想要的嗎? –

+0

好的,我接受了你的建議並刪除了一些我很確定我不會使用的模塊。剩下的我相信我會用。我試着做pygame.time.delay(5000),但沒有奏效。這裏是我的代碼現在的腳本。對不起,代碼不集中在這個。 while play == True: welcome_screen() pygame.display.update() pygame.time.delay(5000) play = False –

+0

我試圖評論,因爲它給我的問題xd。我想讓消息在離開綠色屏幕5秒後消失,而不是退出程序。 –