📜  在Python Arcade 中添加背景图像

📅  最后修改于: 2022-05-13 01:55:39.732000             🧑  作者: Mango

在Python Arcade 中添加背景图像

在本文中,我们将学习如何在Python为街机游戏添加背景图像。

添加背景图像

我们将使用下面的图片作为我们的背景图片。

因此,要将此图像添加为我们的背景图像,我们将使用 load_texture() 和 draw_texture_rectangle()函数。

加载纹理():

load_texture函数用于从 Arcade 中的文件导入纹理。



draw_texture_rectangle():

draw_texture_rectangle函数用于导入具有特定坐标的纹理。

下面是实现:

Python3
# Importing arcade module
import arcade
  
# Creating MainGame class
class MainGame(arcade.Window):
    def __init__(self):
        super().__init__(600, 600, title = "Background Image")
  
        # Loading the background image
        self.background = arcade.load_texture("BACKGROUND.png")
  
    # Creating on_draw() function to draw on the screen
    def on_draw(self):
        arcade.start_render()
          
        # Drawing the background image
        arcade.draw_texture_rectangle(300, 300, 600,
                                      600, self.background)
  
# Calling MainGame class
MainGame()
arcade.run()


输出: