Pygame mouse cursor load/unload

Ian Kelly ian.g.kelly at gmail.com
Sun Mar 10 20:23:29 CET 2013


On Sat, Mar 9, 2013 at 5:25 PM, Alex Gardner <agardner210 at gmail.com> wrote:
> On Saturday, March 2, 2013 7:56:31 PM UTC-6, Alex Gardner wrote:
>> I am in the process of making a pong game in python using the pygame library.  My current problem is that when I move the mouse, it turns off as soon as the mouse stops moving.  The way I am doing this is by making the default cursor invisible and using .png files as replacements for the cursor.  Perhaps my code would best explain my problem.  I will take help in any way that I can.  Here are the links that contain my code:
>>
>>
>>
>> Main class:  http://pastebin.com/HSQzX6h2
>>
>> Main file (where the problem lies):  http://pastebin.com/67p97RsJ
>>
>>
>>
>> If the links yield nothing, please let me know (agardner210 at gmail.com)
>
> I would like to bother you fine folks one last time!  There are drawing problems that I am running into.  The paddle keeps on moving but it doesn't rewrite the black paddle.  This is a problem because the paddle just keeps leaving a green trail.  The code is here:  http://pastebin.com/gVPPJYWs
>
> I feel as though I am missing something...

You get the streaking because the first blanking operation only ever
blanks at (0, 0), and the second one blanks at the new paddle
position, not the previous position.

You don't need two separate rects to keep track of where the paddle
is.  blank_rect and b_bounds_rect are entirely unnecessary, so get rid
of them.

The line "screen.blit(bpaddle, paddle_pos)" should be replaced with
"screen.blit(bpaddle, paddle_rect)", because paddle_rect is what
you're using to track the paddle location.  Since paddle_pos is not
being updated, the former would always draw the blank paddle in the
upper-left corner.  This should also be the only place where you're
blanking the paddle, so get rid of the other one.

You also don't need the if statement at all.  The clamping operation
already ensures that the paddle is bounded to the region (0, 0, 300,
300).

Once that's gone, you no longer need paddle_pos at all, so you can
delete that as well.



More information about the Python-list mailing list