我正在为我正在制作的游戏制作关卡编辑器。我已将其设置为可以将图片放入文件夹中,并将其从90x90像素块拆分为可在编辑器中使用的9个30x30像素块。制作30x30块的代码如下所示:
one = Image.new('RGBA',(30,30),(255,255,255,0))
two = Image.new('RGBA',(30,30),(255,255,255,0))
three = Image.new('RGBA',(30,30),(255,255,2550,0))
four = Image.new('RGBA',(30,30),(255,255,255,0))
five = Image.new('RGBA',(30,30),(255,255,255,0))
six = Image.new('RGBA',(30,30),(255,255,2550,0))
seven = Image.new('RGBA',(30,30),(255,255,2550,0))
eight = Image.new('RGBA',(30,30),(255,255,255,0))
nine = Image.new('RGBA',(30,30),(255,255,255,0))
for y in range(1,iy):
print ((y/9)*10),"%"
for x in range(1,ix):
pixel = im.getpixel((x,y))
if y<30:
if x<30:
one.putpixel((x,y),pixel)
elif x<60:
four.putpixel((x-30,y),pixel)
else:
seven.putpixel((x-60,y),pixel)
elif y <60:
if x <30:
two.putpixel((x,y-30),pixel)
elif x <60:
five.putpixel((x-30,y-30),pixel)
else:
eight.putpixel((x-60,y-30),pixel)
else:
if x < 30:
three.putpixel((x,y-60),pixel)
elif x < 60:
six.putpixel((x-30,y-60),pixel)
else:
nine.putpixel((x-60,y-60),pixel)
add = [im,one,two,three,four,five,six,seven,eight,nine]
bdict[s]= add
cd = os.getcwd()+'\\'+s +'\\'
one.save(cd + s +'one.png')
two.save(cd+s+'two.png')
three.save(cd+s+'three.png')
four.save(cd+s+'four.png')
five.save(cd+s+'five.png')
six.save(cd+s+'six.png')
seven.save(cd+s+'seven.png')
eight.save(cd+s+'eight.png')
nine.save(cd+s+'nine.png')
im.save(cd + fol)
im = os.getcwd()+'\\'+fol
one = os.getcwd()+'\\'+s+'one.png'
two =os.getcwd()+'\\'+s+'two.png'
three =os.getcwd()+'\\'+s+'three.png'
four = os.getcwd()+'\\'+s+'four.png'
five =os.getcwd()+'\\'+s+'five.png'
six =os.getcwd()+'\\'+s+'six.png'
seven =os.getcwd()+'\\'+s+'seven.png'
eight =os.getcwd()+'\\'+s+'eight.png'
nine =os.getcwd()+'\\'+s+'nine.png'
add = [im,one,two,three,four,five,six,seven,eight,nine]
bdict[s]= add
maxes[0]+=1
当两个块重叠时,它们会有这个奇怪的白条,它只显示在左上方和右上方以及左下方和右下方的区块周围。看起来像这样:
可能有错误的唯一其他地方是代码加载精灵的地方,这里: grounds是一个包含不同矩形的数组,而gsprites是一个包含Pygame加载的格式的不同精灵的数组。
for number in range(0,len(grounds)):
cr = grounds[number]
cr.left += xscroll
cr.top += yscroll
pygame.draw.rect(windowsurface,clear,cr)
change = pygame.transform.scale(gsprites[number],(30,30))
windowsurface.blit(gsprites[number],cr)
cr.left -= xscroll
cr.top -= yscroll
我正在运行windows vista 32位。
答案 0 :(得分:0)
没关系,我明白了。我在制作精灵之前绘制了一个矩形,它最终出现在精灵下面。