栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

通过单击面向对象的PyGame按钮来调用PyGame函数

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

通过单击面向对象的PyGame按钮来调用PyGame函数

您必须调用

pg.display.flip()
Menu
函数。

我还对代码结构有一些建议。我将使用另一个函数或类(

main
在这种情况下)来管理不同的场景。因此,我首先将当前场景函数分配给变量,然后在主while循环中调用它。场景完成后,我返回下一个场景并将其分配给
scene
变量以交换场景。如果您直接从另一个场景中直接调用下一个函数,则可以避免潜在的递归错误(尽管在简单的游戏或应用中,您不可能超过1000的递归限制)。

import pygame as pgpg.init()screen = pg.display.set_mode((600, 400))clock = pg.time.Clock()BLUE = pg.Color('dodgerblue3')ORANGE = pg.Color('sienna3')def front_page():    while True:        for event in pg.event.get(): if event.type == pg.QUIT:     return None # Press a key to return the next scene. elif event.type == pg.KEYDOWN:     return menu        screen.fill(BLUE)        pg.display.flip()        clock.tick(60)def menu():    while True:        for event in pg.event.get(): if event.type == pg.QUIT:     return None # Press a key to return the next scene. elif event.type == pg.KEYDOWN:     return front_page        screen.fill(ORANGE)        pg.display.flip()        clock.tick(60)def main():    scene = front_page  # Set the current scene.    while scene is not None:        # Execute the current scene function. When it's done        # it returns either the next scene or None which we        # assign to the scene variable.        scene = scene()main()pg.quit()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/638074.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号