图像目录和cx_Freeze

问题描述 投票:2回答:1

所以基本上我想将.py脚本转换为可执行文件。唯一的问题是setup.py文件必须与图像和声音文件位于同一目录中,而我的游戏文件位于使用setup.py的目录上方。 我如何编辑安装文件,以便我不必四处转换并更改我的游戏文件中的所有代码?如果需要,我将编辑游戏文件,但最好不要。

from os import path

img_dir = path.join(path.dirname(__file__), 'img')
snd_dir = path.join(path.dirname(__file__), 'snd')

#ways i load in images:
background = pygame.image.load(path.join(img_dir, 
"background.jpg")).convert()

alien_images = []
alien_list = ['alien1.png', 'alien2.png']
for img in alien_list:
    alien_images.append(pygame.image.load(path.join(img_dir, 
                                                    img)).convert())`

这是我现在拥有的安装文件。除了当然无法找到图像和声音外,它没有错误。

import cx_Freeze

executables = [cx_Freeze.Executable("Shmup.py")]

cx_Freeze.setup(
    name = "Shoot 'm up!",
    options = {"build_exe": {"packages":["pygame"],
                         "include_files": ["alien1.png", "alien2.png",
                                            "background.jpg", "laser1.png",
                                            "powerUp.png", "shield.png",
                                            "regularExplosion00.png", 
                                            "regularExplosion01.png",
                                            "regularExplosion02.png", 
                                            "regularExplosion03.png",
                                            "regularExplosion04.png", 
                                            "regularExplosion05.png",
                                            "regularExplosion06.png", 
                                            "regularExplosion07.png",
                                            "regularExplosion07.png", 
                                            "regularExplosion08.png",
                                            "regularExplosion09.png", 
                                            "ship1.png",
                                            "sonicExplosion00.png", 
                                            "sonicExplosion01.png",
                                            "sonicExplosion02.png", 
                                            "sonicExplosion03.png",
                                            "sonicExplosion04.png", 
                                            "sonicExplosion05.png",
                                            "sonicExplosion06.png", 
                                            "sonicExplosion07.png",
                                            "sonicExplosion08.png", 
                                            "sonicExplosion09.png",
                                            "Expl.wav", "Expl2.wav", 
                                            "Music.ogg", "Pew.wav",
                                            "Powerup.wav", "Rumble.ogg"]}},
    executables = executables
    )
python python-3.x module cx-freeze
1个回答
0
投票

您可以在“include_files”指令中包含相对目录。像这样的东西:

include_files = [("game_assets", "assets")]

这会将目录“game_assets”中的所有文件复制到目标目录“assets”。当然,您可以使用任何您想要的名称!

© www.soinside.com 2019 - 2024. All rights reserved.