第1步-安装并打开窗口#
我们的第一步是确保一切都安装好了,至少可以打开一扇窗户。
安装#
确保安装了Python。 Download Python here 如果你还没有的话。
确保 Arcade library 已安装。
您应该首先设置一个虚拟环境(Venv)并将其激活。
使用安装Arade
pip install arcade
。以下是较长的,官方 安装 。
打开一扇窗#
下面的示例打开了一个空白窗口。设置一个项目并运行下面的代码。
01_Open_window.py-打开窗口#
1"""
2Platformer Game
3
4python -m arcade.examples.platform_tutorial.01_open_window
5"""
6import arcade
7
8# Constants
9SCREEN_WIDTH = 800
10SCREEN_HEIGHT = 600
11SCREEN_TITLE = "Platformer"
12
13
14class MyGame(arcade.Window):
15 """
16 Main application class.
17 """
18
19 def __init__(self):
20
21 # Call the parent class to set up the window
22 super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
23
24 self.background_color = arcade.csscolor.CORNFLOWER_BLUE
25
26 def setup(self):
27 """Set up the game here. Call this function to restart the game."""
28 pass
29
30 def on_draw(self):
31 """Render the screen."""
32
33 # The clear method should always be called at the start of on_draw.
34 # It clears the whole screen to whatever the background color is
35 # set to. This ensures that you have a clean slate for drawing each
36 # frame of the game.
37 self.clear()
38
39 # Code to draw other things will go here
40
41
42def main():
43 """Main function"""
44 window = MyGame()
45 window.setup()
46 arcade.run()
47
48
49if __name__ == "__main__":
50 main()
结果应该是这样的窗口:

一旦您让代码正常工作,尝试找出如何调整代码,以便您可以:
更改屏幕大小(甚至使窗口可调整大小或全屏)
更改标题
更改背景颜色
请参阅的文档 Arcade.COLOR包
请参阅的文档 Arcade.css颜色包
请浏览文档以了解
arcade.Window
类来了解它所能做的一切。
运行本章#
python -m arcade.examples.platform_tutorial.01_open_window