这是我在这里的第一篇文章。我看到了很多类似的问题,但我的具体情况有点儿。为了进入主题我需要使用python执行单个文件可执行文件,我使用py2exe和Iexpress。一切都很完美,直到昨天我还包括图片(.png)。用py2exe编译之后一切正常,所以我很确定pygame能够打开.png但是当我用Iexpress压缩时,我认为只能将它们解压缩到临时文件夹中我得到:
“Traceback(最近一次调用最后一次): 文件“Game.py”,第23行,in pygame.error:文件不是Windows BMP文件“
所以我得到了两个完全相同的文件夹,第一个是pre-iexpress工作,第二个临时文件夹没有。 我使用Python 3.4和pygame-1.9.2a0-cp34 这是我的代码
__author__ = 'Xpd'
back = "bg.png"
sh = "ship.png"
ali = "alien.png"
import pygame
import random
import sys
pygame.init()
white = (255,255,255)
black = (0,0,0)
red = (255,0,0)
green =(0,255,0)
blue = (0,0,255)
display_width = 800
display_height = 600
clock = pygame.time.Clock()
gameDisplay = pygame.display.set_mode((display_width,display_height), 0, 0)
pygame.display.set_caption('Invaders')
background = pygame.image.load(back)
ship = pygame.image.load(sh)
alien = pygame.image.load(ali)
def Intro():
Intro = True
while Intro == True:
gameDisplay.fill(green)
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
Intro = False
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
def text_to_button(msg, color, buttonx, buttony, buttonwidth, buttonheight, size = "small"):
textSurf, textRect = text_objects(msg,color,size)
textRect.center = ((buttonx+(buttonwidth/2)), buttony+(buttonheight/2))
gameDisplay.blit(textSurf, textRect)
return textSurface, textSurface.get_rect()
def text(msg,color, y_displace=0, size = "small"):
textSurf, textRect = text_objects(msg,color, size)
textRect.center = (display_width / 2), (display_height / 2)+y_displace
gameDisplay.blit(textSurf, textRect)
def GameLoop():
gameExit = False
gameOver = False
prime_x = display_width/2
block = 3
fps=300
alien_x = random.randrange(50,300)
alien_y = random.randrange(50,300)
alien_health = 1
ship_health = 3
ship_damage = 1
bulletspeed = 0
bullet_y = 550
bullet_x = -50
bullet_size = 5
movement = 0
while gameOver == True:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_q:
gameExit = True
if event.key == pygame.K_c:
GameLoop()
while not gameExit:
if prime_x <= 0:
prime_x = 0
if prime_x >= 790:
prime_x = 790
for event in pygame.event.get():
print(event)
if event.type == pygame.QUIT:
gameExit = True
gameQuit = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
movement = -block
if event.key == pygame.K_RIGHT:
movement = block
if event.key == pygame.K_SPACE:
if bullet_y < 0:
bullet_y = 550
if bullet_y == 550:
bulletspeed = -bullet_size
bullet_x = prime_x
if bullet_y < 0:
bullet_y = 550
if event.type == pygame.KEYUP:
if event.key == pygame.K_RIGHT or pygame.K_LEFT:
movement = 0
if alien_x < bullet_x < alien_x + 50 or alien_x < bullet_size + bullet_x < alien_x + 50:
if alien_y < bullet_y < alien_y + 50 or alien_y < bullet_size + bullet_y < alien_y + 50:
alien_health -= ship_damage
bulletspeed = 0
bullet_y = 550
bullet_x = -50
if alien_health <= 0:
alien_x = random.randrange(50,300)
alien_y = random.randrange(50,300)
alien_health = 1
prime_x += movement
bullet_y += bulletspeed
pygame.draw.rect(gameDisplay, green,[alien_x,alien_y,50 ,50 ] )
gameDisplay.blit(background, (0,0))
gameDisplay.blit(alien, (alien_x,alien_y))
gameDisplay.blit(ship, (prime_x-22,545))
pygame.draw.rect(gameDisplay, red, [bullet_x, bullet_y,bullet_size, bullet_size])
pygame.display.update()
clock.tick(fps)
Intro()
GameLoop()
pygame.quit()
sys.exit()
我在Iexpress内部放置: alien.png,bg.png,Game.exe,SDL.dll,SDL_IM~1.dll,SDL_MI~1,SDL_ttf.dll,ship.png,smpeg.dll
道歉,如果我在这里做错了,这是我的第一个项目。
编辑:pygame.image.get_extended()返回1,使用经过Windows 8.1测试的Iexpress 32bit和64bit仍无效。答案 0 :(得分:1)
我无法发表评论,所以这里是'答案'...... 你的python看起来不错。我认为它是IExpress,这很棒,但排除故障可能有点棘手。以下是我要尝试的事情:
UseLongFileName=1
*.sed
)
ShowInstallProgramWindow=3
HideExtractAnimation=0
AppLaunched=cmd /C "echo begin&&pause&&echo end"
注意:确保您拥有ShowInstallProgramWindow=3
,因此您希望隐藏进程等待用户输入 - 锁定资源。
AppLaunched=cmd /C "copy * C:\some\folder\&&pause"
import os
org = open('original.bmp','rb')
new = open('new.bmp','rb')
size_compared = 0
comp_size = 1
MAX_SIZE = max(os.path.getsize(i) for i in ('original.bmp','new.bmp'))
print 'comparing bytes...'
while True:
a = org.read[comp_size]
b = new.read[comp_size]
size_compared += comp_size
if a!=b:
print 'bytes don't match!'
print '{} != {}'.format(a,b)
print 'at byte {}'.format(size_compared)
break
if a=='' and b=='': break # files are empty
if MAX_SIZE < size_compared: break # just in case... shouldn't happen...
org.close()
new.close()
print 'done comparing... anything found?'
如果您有任何疑问,请询问 - 享受。