[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Image tile help



On Monday 08 October 2001 15:21, you wrote:
> I am having a 128x128 tilemap (with 32x32 tiles), and I want to make a
> small tile engine. Seeing that python can do more without using the normal
> 2x2 array lib, I was wondering how can I clip a specific portion of the
> tile map, and then add all the clipped parts to a surface (or one by one)
> and flip it as a background/foreground...
>
> Has anyone done this?
>
> -Panos

I used the following code to tile a single bitmap onto the screen using an 
x,y offset to allow scrolling. With a few simple changes, it should be able 
to handle a tile engine.

Pete, if you want to add this code to the repository, feel free. It's the 
same code you saw in the cyclone test on #pygame :)

def tile_bg(screen, image, xoffset, yoffset):
 
    ax, ay = 0, 0
    aw, ah = screen.get_size()
    bw, bh = image.get_size()
 
    xp = 0
    while xp < aw:
        dx = ax + xp
        sx = (dx + xoffset) % bw
        dw = bw - sx
        sw = dw
        if dx + dw > ax + aw:
            dw = ax + aw - dx
            sw = dw
        yp = 0
        while yp < ah:
            dy = ay + yp
            sy = (dy + yoffset) % bh
            sh = dh = bh - sy
            if dy + dh > ay + ah:
                dh = ay + ah - dy
                sh = dh
            sr = (sx,sy,sw,sh)
            dr = (dx,dy,dw,dh)
            screen.blit(image, dr, sr)
            yp = yp + sh
        xp = xp + sw
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org