我和我的朋友一直致力于一个大型项目,以便在python和PyGame中学习和娱乐.基本上它是一个小村庄的AI模拟.我们想要一个日/夜循环,所以我找到了一种利用numpy改变整个表面颜色的巧妙方法(特别是交叉渐变教程) - http://www.pygame.org/docs/tut/surfarray/SurfarrayIntro. HTML
我将它实现到代码中并且工作正常,但速度非常慢,比如<1 fps slow.所以我看看线程(因为我想最终添加它)并在队列中找到这个页面 - 在python中学习队列模块(如何运行它)
我花了大约15分钟制作一个基本系统,但是一旦我运行它,窗口关闭,它说
Exception in thread Thread-1 (most likely raised during interpreter shutdown):
Run Code Online (Sandbox Code Playgroud)
编辑:这就是它所说的全部,没有回溯错误
我不知道我做错了什么,但我想我错过了一些简单的事情.我在下面添加了代码的必要部分.
q_in = Queue.Queue(maxsize=0)
q_out = Queue.Queue(maxsize=0)
def run(): #Here is where the main stuff happens
#There is more here I am just showing the essential parts
while True:
a = abs(abs(world.degree-180)-180)/400.
#Process world
world.process(time_passed_seconds)
blank_surface = pygame.Surface(SCREEN_SIZE)
world.render(blank_surface) #The world class renders everything onto a blank surface
q_in.put((blank_surface, a))
screen.blit(q_out.get(), (0,0))
def DayNight():
while True:
blank_surface, a = …Run Code Online (Sandbox Code Playgroud)