第1步-安装并打开窗口#

我们的第一步是确保一切都安装好了,至少可以打开一扇窗户。

安装#

  • 确保安装了Python。 Download Python here 如果你还没有的话。

  • 请确保 Arcade library 已安装。

    • 您应该首先设置一个虚拟环境(Venv)并将其激活。

    • 使用安装Arcade pip install arcade

    • 以下是较长的,官方 安装说明

我强烈推荐使用免费社区版的PyCharm作为编辑。如果您这样做,请参见 安装带有PyCharm和虚拟环境的Arcade

打开一扇窗#

下面的示例打开了一个空白窗口。设置一个项目并运行下面的代码。(它在压缩文件中也是 01_open_window.py 。)

注解

这是一个固定大小的窗口。有可能会有一个 可调整大小的窗口 或者是 全屏示例 ,但我们可以先做更有趣的事情。因此,在本教程中,我们将坚持使用固定大小的窗口。

01_Open_window.py-打开窗口#
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
Platformer Game
"""
import arcade

# Constants
SCREEN_WIDTH = 1000
SCREEN_HEIGHT = 650
SCREEN_TITLE = "Platformer"


class MyGame(arcade.Window):
    """
    Main application class.
    """

    def __init__(self):

        # Call the parent class and set up the window
        super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)

        arcade.set_background_color(arcade.csscolor.CORNFLOWER_BLUE)

    def setup(self):
        """Set up the game here. Call this function to restart the game."""
        pass

    def on_draw(self):
        """Render the screen."""

        self.clear()
        # Code to draw the screen goes here


def main():
    """Main function"""
    window = MyGame()
    window.setup()
    arcade.run()


if __name__ == "__main__":
    main()

结果应该是这样的窗口:

../../_images/step_01.png

一旦代码正常工作,就可以确定如何调整代码,以便能够: