Contents Menu Expand Light mode Dark mode Auto light/dark mode
Python Arcade 3.0.0.dev27
Light Logo Dark Logo
Python Arcade 3.0.0.dev27

开始

  • 什么是Arcade?
  • 从这里开始
  • 安装
    • 在Windows上安装
    • 在Mac上安装
    • 在Linux上安装
    • 从源安装
    • 在PyCharm中设置虚拟环境
    • 安装过时的Python版本
  • 如何获得帮助

实例

  • How-to示例代码
  • Python Discord GameJam2020
  • 用Arade制作的游戏

教程

  • 简单平台
    • 第1步-安装并打开窗口
    • 第2步-纹理和雪碧
    • 第3步-多款雪碧和SpriteList
    • 第4步-添加用户控件
    • 第5步-添加重力
    • 步骤6-重置
    • 第7步-添加摄像头
    • 第八步--收集硬币
    • 第9步-添加声音
    • 第10步-添加分数
    • 第11步-使用场景
    • 第12步-从地图编辑器加载地图
    • 第13步-更多类型的层
    • 第14步-多个级别
  • PyMunk平台
  • 使用开始/结束屏幕的视图
  • 单人纸牌
  • 电灯
  • 使用PyInstaller捆绑游戏
  • 使用Nuitka一起编译游戏
  • 着色器
    • 光线投射阴影
    • CRT滤光片
    • 着色器玩具-发光
    • 着色器玩具粒子
    • 计算着色器
    • GPU粒子爆发
    • 使用着色器
  • 用Arade的图形用户界面制作菜单
  • 使用FrameBuffer对象

导览

  • 绘制和使用精灵
    • 使用Sprite和SpriteList绘制
    • 高级SpriteList技术
  • 键盘
  • 声响
  • 纹理
  • 分段
  • GUI
    • 图形用户界面概念
    • 图形用户界面风格
    • 故障排除和提示
  • 纹理地图集
  • 边缘伪影
  • 日志记录
  • OpenGL
  • 性能
  • 无头Arcade
  • 垂直同步
  • 比较Pygame

API

  • Index
  • Reference
    • 类型
    • 绘图-基本体
    • 形状列表
    • 绘图-实用程序
    • 小精灵
    • 精灵列表
    • 精灵场景
    • 文本
    • 切片地图阅读器
    • 纹理管理
    • 纹理变换
    • 纹理地图集
    • 性能信息
    • 物理引擎
    • 其他实用程序功能
    • 几何图形支持
    • 游戏控制器支持
    • 操纵杆支撑
    • 窗口和视图
    • 声响
    • 寻路
    • 等轴测贴图支持(不完整)
    • 耳夹
    • 放松
    • OpenGL上下文
    • 数学
    • OpenGL
      • 语境
      • 纹理
      • 缓冲层
      • BufferDescription
      • 几何图形
      • 帧缓冲
      • 查询
      • 计划
      • 计算着色器
      • 例外情况
    • GUI
    • 图形用户界面小部件
    • 图形用户界面事件
    • 图形用户界面属性
    • 图形用户界面风格
    • 图形用户界面的实验特征
    • Arcade.key包
    • Arcade.css颜色包
    • Arcade.COLOR包
  • 内置资源

源代码

  • GitHub
  • 发行说明
  • 许可证
  • 为拱廊做出贡献
  • 发布检查清单

社交

  • 不和谐(最活跃的点)
  • Reddit/r/pythonarcade
  • 推特@ArcadeLibrary
  • 邮箱:Instagram@PythonArcadeLibrary
  • 邮箱:Facebook@ArcadeLibrary
  • 不同的编码者

学习资源

  • 书籍-学习使用Arade编程
  • 使用Arade和 Python Banyan进行点对点游戏
  • 美国PYCON 2022会谈
  • 美国PyCon 2019教程
  • 澳大利亚PYCON 2018年多人游戏
  • 2018年美国PYCON演讲
Back to top

MENU_03.py完整列表#

menu_03.py#
  1"""
  2Menu.
  3
  4Shows the usage of almost every gui widget, switching views and making a modal.
  5"""
  6import arcade
  7import arcade.gui
  8
  9# Screen title and size
 10SCREEN_WIDTH = 800
 11SCREEN_HEIGHT = 600
 12SCREEN_TITLE = "Making a Menu"
 13
 14
 15class MainView(arcade.View):
 16    """This is the class where your normal game would go."""
 17
 18    def __init__(self):
 19        super().__init__()
 20
 21        self.manager = arcade.gui.UIManager()
 22
 23        switch_menu_button = arcade.gui.UIFlatButton(text="Pause", width=150)
 24
 25        # Initialise the button with an on_click event.
 26        @switch_menu_button.event("on_click")
 27        def on_click_switch_button(event):
 28            # Passing the main view into menu view as an argument.
 29            menu_view = MenuView(self)
 30            self.window.show_view(menu_view)
 31
 32        # Use the anchor to position the button on the screen.
 33        self.anchor = self.manager.add(arcade.gui.UIAnchorLayout())
 34
 35        self.anchor.add(
 36            anchor_x="center_x",
 37            anchor_y="center_y",
 38            child=switch_menu_button,
 39        )
 40
 41    def on_hide_view(self):
 42        # Disable the UIManager when the view is hidden.
 43        self.manager.disable()
 44
 45    def on_show_view(self):
 46        """ This is run once when we switch to this view """
 47        arcade.set_background_color(arcade.color.DARK_BLUE_GRAY)
 48
 49        # Enable the UIManager when the view is showm.
 50        self.manager.enable()
 51
 52    def on_draw(self):
 53        """ Render the screen. """
 54        # Clear the screen
 55        self.clear()
 56
 57        # Draw the manager.
 58        self.manager.draw()
 59
 60
 61class MenuView(arcade.View):
 62    """Main menu view class."""
 63
 64    def __init__(self, main_view):
 65        super().__init__()
 66
 67        self.manager = arcade.gui.UIManager()
 68
 69        resume = arcade.gui.UIFlatButton(text="Resume", width=150)
 70        start_new_game = arcade.gui.UIFlatButton(text="Start New Game", width=150)
 71        volume = arcade.gui.UIFlatButton(text="Volume", width=150)
 72        options = arcade.gui.UIFlatButton(text="Options", width=150)
 73
 74        exit = arcade.gui.UIFlatButton(text="Exit", width=320)
 75
 76        # Initialise a grid in which widgets can be arranged.
 77        self.grid = arcade.gui.UIGridLayout(column_count=2, row_count=3, horizontal_spacing=20, vertical_spacing=20)
 78
 79        # Adding the buttons to the layout.
 80        self.grid.add(resume, col_num=0, row_num=0)
 81        self.grid.add(start_new_game, col_num=1, row_num=0)
 82        self.grid.add(volume, col_num=0, row_num=1)
 83        self.grid.add(options, col_num=1, row_num=1)
 84        self.grid.add(exit, col_num=0, row_num=2, col_span=2)
 85
 86        self.anchor = self.manager.add(arcade.gui.UIAnchorLayout())
 87
 88        self.anchor.add(
 89            anchor_x="center_x",
 90            anchor_y="center_y",
 91            child=self.grid,
 92        )
 93
 94        self.main_view = main_view
 95
 96    def on_hide_view(self):
 97        # Disable the UIManager when the view is hidden.
 98        self.manager.disable()
 99
100    def on_show_view(self):
101        """ This is run once when we switch to this view """
102
103        # Makes the background darker
104        arcade.set_background_color([rgb - 50 for rgb in arcade.color.DARK_BLUE_GRAY])
105
106        # Enable the UIManager when the view is showm.
107        self.manager.enable()
108
109    def on_draw(self):
110        """ Render the screen. """
111        # Clear the screen
112        self.clear()
113        self.manager.draw()
114
115
116def main():
117    window = arcade.Window(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE, resizable=True)
118    main_view = MainView()
119    window.show_view(main_view)
120    arcade.run()
121
122
123if __name__ == "__main__":
124    main()
Copyright © 2024, Paul Vincent Craven
Made with Sphinx and @pradyunsg's Furo