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

Re: [pygame] Update performance



>  > Would it be even faster to just have the sprite return a padded
rectangle?
>  > It's bounding box plus it's maximum movement per cycle added to each
side.
>  > This would take care of getting a union of it's current place and the
place
>  > it was just at (5 pixels to the left).  Does that make sense?
>
> Yes, this would work well. Note however that rect.union() is a _very_
> fast function - it costs you almost nothing to call it. Calculating
> the padded rect in python may take longer.

the rectangles also have an inflate() command which can easily
expand and shrink a rectangle. this would be an easy way to get
a slightly larger rectangle. i still would think that doing a
union between the cleared and newly drawn position might be
slightly faster. plus it will work in all cases, just in case
the sprite moves a little to fast or is warped around on any
given frame.

i think in reality, both methods will work the same. the
advantage of just expanding the rectangle for the current blit is
you don't need to keep a variable to hang on to the old position.


also remember that python includes a pretty good, basic profiler.
i've been able to root out some ugly code using it. unfortunately,
the profiler doesn't give specific times for calls to python C
extensions, so sometimes it's hard to tell if it is your code or
the calls to pygame that are taking the cpu.


____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org