On Tue, Jun 15, 2010 at 9:53 PM, Hokan LUNDBERG
<hokan@xxxxxxxx> wrote:
Gumm:
> Why do you want the rect to be smaller than the cloud image; what are
you trying to accomplish?
I want to avoid that the plane is hit by a cloud
just by being close to it. The rect of the cloud-sprite is bigger than the cloud
image (since it is not rectangular), so when one play the plane game (http://www.cs.iupui.edu/~aharris/pygame/ch07/)
one sometimes gets the feeling "no, the plane did not touch the cloud!" and
still looses a plane. The author of the book recommends to use
the inflate-method, and has it in one version of the game (http://www.cs.iupui.edu/~aharris/pygame/ch07/mpScore.py),
that helps for the right side of the clouds but not for the left side.. How to
fix that?
Since the Sprite.Group uses the sprite's rect to draw, you should not modify its size. what you are seeing is a side effect of that. There is a more elegant way. Let me draw your attention to the sprite_collide function of Sprite class; specifically to the function's "collided" argument, which is the name of a collision-testing function to call.
The Sprite class also provides some callback functions that are ready for you to use with sprite_collide.
If you want to use the cloud's rect, you should check out the collide_rect_ratio callback function. This is essentially what you were hoping to do by resizing the cloud's rect--but without side effects. However, it has the drawback of strange collisions at the "corners" of clouds.
Since clouds are not rectangular, but sort of round, I prefer collide_circle. Using this callback function will avoid strange collisions at a rect's corners.
An other question: Is there something like
JOptionPane.showInputDialog() in some GUI library for Python? I.e. being able
to show a dialox box for input by just one line of code. (My students
like the dialog boxes of JOptionPane in Java very much and have asked me
how to do the same thing in Python.)
Thanks,
Hokan
I haven't personally tried Albow, but I see it frequently recommended on this mailing list. See
pygame.org.