[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Background texture



Oh! Exactly what I want :D
Thank you!!!


On Wed, 21 May 2003 11:42:21 -0700
Pete Shinners <pete@shinners.org> wrote:

> Choplair wrote:
> > I've a 800*600px window and I want put in the background a small
> > image texture which is 10*10px!
> > 
> > Can you tell me how I can fill this texture in a all the window
> > (without creating a big 800*600 image.. T_T) ?
> 
> the way to do this would be tile the image by hand. if your performance 
> needs aren't too tight a generic function would do the trick, i think i 
> can whip one up right in this email..
> 
> def tileblit(src, dst):
>      srcw, srch = src.get_size()
>      dstw, dsth = dst.get_size()
>      for y in range(0, dsth, srch):
>          for x in range(0, dstw, srcw):
>              dst.blit(src, (x, y))
> 
> the biggest optimization you'd probably want is to limit this blit to a 
> rectangular area. it is easy to use this with a full sized background 
> image, but a bit of extra work for the tiling. here is a function that 
> should do it.
> 
> def tileblitarea(src, dst, rectarea):
>      srcw, srch = src.get_size()
>      oldclip = dst.get_clip()
>      dst.set_clip(rectarea)
>      top = rectarea.top - rectarea.top % srch
>      left = rectarea.left - rectarea.left % srcw
>      for y in range(top, rectarea.bottom, srch):
>          for x in range(left, rectarea.right, srcw):
>              dst.blit(src, (x, y))
>      dst.set_clip(oldclip)
> 
> these tile blitting functions will work for source images of any size.
> 
> 


--------------
Choplair
choplair AT fr DOT st