1

我正在为我正在开发的游戏制作关卡编辑器。我进行了设置,以便您可以将图片放入文件夹中,它会将其从 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 是一个数组,包含不同 sprite 的格式,它们由 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 位。

4

1 回答 1

0

没关系,我想通了。在对精灵进行 blitting 之前,我正在绘制一个矩形,它最终出现在精灵下方。

于 2012-06-26T23:37:07.750 回答