[英]calling functions python (pygame)
I am tying to have a load of functions where by when i call each function on the screen function, it displays stuff i want on the screen. 我想拥有大量的功能,当我在屏幕上调用每个功能时,它会在屏幕上显示我想要的东西。 Im having trouble with this simple program.
我在这个简单的程序上遇到了麻烦。 I would like to display text on the screen when i write to it.
我想在屏幕上显示文字。 but all its doing is displaying the screen.
但它所做的只是显示屏幕。
import pygame
from pygame.locals import *
pygame.init()
def screen(width,height,name):
screen = pygame.display.set_mode((600,600))
screen=pygame.display.set_mode((width,height))
return screen
def name(name=""):
pygame.font.init()
myfont = pygame.font.SysFont("monospace", 15)
label = myfont.render("Some text!", 1, (255,255,0))
result=screen(640,480,name).blit(label, (100, 100))
return result
screen(640,480,name("donkey from shrek"))
this is what happens (if I get it right): 这是发生的情况(如果我做对了):
Hope that helps ;) 希望能有所帮助;)
On first glance, i believe you are calling the screen function twice, and thus creating two screens. 乍一看,我相信您会两次调用屏幕功能,从而创建两个屏幕。
The function "name" creates a screen with a label. 函数“名称”创建带有标签的屏幕。 This function is called in the last line of your code, before the "screen" function is called.
在调用“屏幕”函数之前,在代码的最后一行中调用此函数。
When eventually the "screen" function is called (again) in the last line, this will create a new screen, without label... . 最终在最后一行中再次调用“屏幕”功能时,这将创建一个没有标签的新屏幕。
Also the function "screen" does not utilize the argument "name" that is given to the function. 同样,函数“屏幕”不使用为函数指定的参数“名称”。 If you want to set the caption of the screen, then i would like to refer to http://www.pygame.org/docs/ref/display.html#pygame.display.set_caption
如果您想设置屏幕的标题,那么我想参考http://www.pygame.org/docs/ref/display.html#pygame.display.set_caption
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.