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

Re: [pygame] set_clip



> Another thing, how are Rects supposed to be created? I apparently need to
> send a Rect to Surface.set_clip()? I tried the obvious Rect(x,y,w,h), but
> that didn't work. Passing a tuple [x,y,w,h] to set_clip() gave me a SDL
> segmentation fault.

i didn't run into problems with set_clip(), i'm curious on how you
are using it. here is some interactive playtime i did.

 D:\cvs\pygame>python
 Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
 Type "copyright", "credits" or "license" for more information.
 >>> import pygame
 >>> pygame.init()
 (2, 0)
 >>> d = pygame.display
 >>> s = d.set_mode((100, 100))
 >>> s.set_clip((20, 20, 60, 60))
 <rect(20, 20, 60, 60)>
 >>> s.fill(123456)
 <rect(20, 20, 60, 60)>
 >>> s.set_clip(((40, 10), (20, 90)))
 <rect(40, 10, 20, 90)>
 >>> s.fill(200)
 <rect(40, 10, 20, 90)>
 >>> s.set_clip(pygame.rect(10, 40, 80, 40))
 <rect(10, 40, 80, 40)>
 >>> d.flip()
 >>> s.fill(630000)
 <rect(10, 40, 80, 40)>
 >>> d.flip()

i've attached my results in a 1K gif.



note that functions that need only a rectstyle arguments can
accept the rectstyle argument without it being enclosed in a
separate sequence. this was not the case with set_clip(), but
i've just updated it on my end. with earlier versions of python,
python did this sort of "auto tupling" for you, they took it out
for python 1.6, but it is still very useful in this situation..
in my "new" version, all are acceptable calls to set_clip

pos = 20, 10
size = 120, 110
surf.set_clip(pos, size)
surf.set_clip(pos + size)
surf.set_clip(20, 10, 120, 110)
r = rect(pos, size)
surf.set_clip(r)
surf.set_clip((20, 10), r[2:])

as you can see, the rectstyle arguments accept just about any
combination of position, size, and rectangle arguments. i found 
this to be extremely helpful, even when working with related
sprites and areas, i find my data is always in mixed formats.
using the rectstyle's saves the step of converting everything
before use.


quickie.gif