2016-08-22 68 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秒后消失,而不是退出程序。 –