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

Re: [pygame] sprite engine



On 4/28/06, Kamilche <klachemin@xxxxxxxxxxx> wrote:
Uh, not so! If I have a background, then a tree, then a ghost in front
of the tree that's translucent, and something about the tree changes...
i dirty only the tree. The 'go through sprites in zorder and draw if it
intersects the dirty rectangle' bit in the main render loop is what
draws the background, tree, AND ghost, though only the tree got 'dirty.'

The method of only drawing sprites where they are dirty (i.e. they
animated or move) you can save quite a lot of time with the right
game, but if you have moving objects behind your static ones, you need
to worry about marking places dirty both before and after you draw if
you want to get things drawn right, in all cases...

For example, what happens when the ghost moves behind the tree? In
that case, the ghost didn't dirty any part of the tree when he drew
the last frame, so next frame the tree won't redraw (even though he
should draw on top of the ghost) If the ghost then draws himself
(either because he knew he's animating, or because he overlapped his
last dirty rect) he'll draw on top of the tree. While it will likely
be fixed next frame, and for a 60 fps game the layer won't likely have
the slightest idea what happened, the human eye is usually very good
at detecting flicker because we are wired to detect motion that we
aren't directly focusing on, so it can end up being a quite odd little
distracting thing.

Basically, my opinion on the more sophisticated dirty rect stuff
(where you avoid drawing your sprites when they are the same from
frame to frame) is that they can be very hard to be flicker free and
bug free in all cases. Even though those approaches can get rather
incredible frame rates with software-only rendering,  I perfer to
avoid using approaches like that in favor of figuring out what simple
game-specific constraints you can exploit in a simple and provably
reliable way (like maybe you can preflatten a bunch of static objects
in a layer and erase to that, etc.) because I really dislike having to
fix graphical bugs and flicker (it's quite hard to write unit tests
for them, for instance)