我在互联网上进行了广泛的搜索,无法找到适合一次运行我的两个功能的情况。基本上,一个函数包含使用箭头键移动笑脸的代码,另一个函数使得红色圆圈从屏幕顶部掉落。这是main.py
中的代码:
import game, prepare
from multiprocessing import Process
prepare.setuppygame()
prepare.setupSM()
prepare.setupRC()
#display score for the first time
prepare.disscore()
#set starting positions for first time
game.setStartingPositions()
if __name__ == '__main__':
p1 = Process(target=game.go)
p1.start()
p2 = Process(target=game.RCfall)
p2.start()
p1.join()
p2.join()
我没有得到一个带有下降圆圈的屏幕,并且能够在笑脸上移动;我得到一个带笑脸的屏幕,你可以四处移动,另一个带有下降圈的pygame屏幕,但不是在一起。为什么多处理不工作?我也愿意使用线程,如果它们可以工作的话。
基础设施:Geany,Python2.7,Windows 7,但为Raspberry Pi编程
答案 0 :(得分:0)
我相信在pygame网站上阅读本教程
http://www.pygame.org/docs/tut/chimp/ChimpLineByLine.html
会让您了解如何完成您想要的任务。它显示了在使用光标移动控制图像时如何使图像在屏幕上自行移动。不完全是你想要的,但非常接近。