Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #40382 > unrolled thread

Pygame mouse cursor load/unload

Started byAlex Gardner <agardner210@gmail.com>
First post2013-03-02 17:56 -0800
Last post2013-03-18 16:05 -0700
Articles 8 on this page of 28 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Pygame mouse cursor load/unload Alex Gardner <agardner210@gmail.com> - 2013-03-02 17:56 -0800
    Re: Pygame mouse cursor load/unload Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-02 20:08 -0700
      Re: Pygame mouse cursor load/unload Alex Gardner <agardner210@gmail.com> - 2013-03-02 19:52 -0800
      Re: Pygame mouse cursor load/unload Alex Gardner <agardner210@gmail.com> - 2013-03-02 19:52 -0800
    Re: Pygame mouse cursor load/unload Alex Gardner <agardner210@gmail.com> - 2013-03-03 14:04 -0800
    Re: Pygame mouse cursor load/unload Alex Gardner <agardner210@gmail.com> - 2013-03-03 14:09 -0800
      Re: Pygame mouse cursor load/unload Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-03 16:47 -0700
    Re: Pygame mouse cursor load/unload Alex Gardner <agardner210@gmail.com> - 2013-03-09 16:20 -0800
    Re: Pygame mouse cursor load/unload Alex Gardner <agardner210@gmail.com> - 2013-03-09 16:25 -0800
      Re: Pygame mouse cursor load/unload Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-10 13:23 -0600
    Re: Pygame mouse cursor load/unload Alex Gardner <agardner210@gmail.com> - 2013-03-10 15:25 -0700
      Re: Pygame mouse cursor load/unload Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-10 19:26 -0600
    Re: Pygame mouse cursor load/unload Alex Gardner <agardner210@gmail.com> - 2013-03-11 09:57 -0700
      Re: Pygame mouse cursor load/unload Alex Gardner <agardner210@gmail.com> - 2013-03-11 10:00 -0700
        Re: Pygame mouse cursor load/unload Alex Gardner <agardner210@gmail.com> - 2013-03-11 10:04 -0700
        Re: Pygame mouse cursor load/unload Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-11 11:24 -0600
    Re: Pygame mouse cursor load/unload Alex Gardner <agardner210@gmail.com> - 2013-03-11 10:33 -0700
      Re: Pygame mouse cursor load/unload Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-11 12:01 -0600
    Re: Pygame mouse cursor load/unload Alex Gardner <agardner210@gmail.com> - 2013-03-11 13:43 -0700
      Re: Pygame mouse cursor load/unload MRAB <python@mrabarnett.plus.com> - 2013-03-11 20:54 +0000
      Re: Pygame mouse cursor load/unload Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-11 15:23 -0600
    Re: Pygame mouse cursor load/unload Alex Gardner <agardner210@gmail.com> - 2013-03-12 16:33 -0700
      Re: Pygame mouse cursor load/unload Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-12 21:00 -0600
    Re: Pygame mouse cursor load/unload Alex Gardner <agardner210@gmail.com> - 2013-03-14 15:16 -0700
      Re: Pygame mouse cursor load/unload Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-14 16:31 -0600
    Re: Pygame mouse cursor load/unload Alex Gardner <agardner210@gmail.com> - 2013-03-14 15:56 -0700
    Re: Pygame mouse cursor load/unload Alex Gardner <agardner210@gmail.com> - 2013-03-18 13:24 -0700
      Re: Pygame mouse cursor load/unload Alex Gardner <agardner210@gmail.com> - 2013-03-18 16:05 -0700

Page 2 of 2 — ← Prev page 1 [2]


#41093

FromIan Kelly <ian.g.kelly@gmail.com>
Date2013-03-11 15:23 -0600
Message-ID<mailman.3208.1363037048.2939.python-list@python.org>
In reply to#41091
On Mon, Mar 11, 2013 at 2:43 PM, Alex Gardner <agardner210@gmail.com> wrote:
> I tried to append what you told me to.  Now it appears that I have a syntax error!  I checked my indentations and they look fine to me, but I get this error:
>
>     paddle_pos = pygame.mouse.get_pos()
>                                       ^
> IndentationError: unindent does not match any outer indentation level

The "for" statement and the statement quoted above should both be at
the same indentation level.  If you look at the code, the "for"
statement is indented 7 spaces whereas the other statement is indented
4 spaces.  You need to make them equal.

> I added "paddle_rect.center = pygame.mouse.get_pos()" and removed the double blank paddles.  I have no idea if it works though because of the parse error!  New code:  http://pastebin.com/maqWCdNB

It won't.  You've removed both the position-clamping code and the
clock tick code entirely.  Why did you do that?  You've also gone from
having two separate lines drawing bpaddle and one line drawing beeper,
to having two separate lines drawing beeper, and not drawing bpaddle
at all.

I think that you need to step back from this and try to understand
better the logical flow that you're trying to implement here.  Once
you understand what it is that you're trying to accomplish, then you
can set it down in code.  The overall flow should look like this:

while True:
    <check for and handle events>
    <update the game state>
    <draw the updated game state>
    <update the screen>
    <go to sleep for a while>

Try to implement each of those things as a discrete unit, and think
hard about what operations need to be done and in what order to
accomplish each of those things.  It might help you conceptually to
split the first three off into separate functions that each do one
specific piece of the above, and then implement each of those
functions thinking only about what that particular function needs to
do.  To provide a concrete example of what I am talking about,
consider replacing your main loop with this:

state = SomeClassRepresentingTheGameState()

while True:
    # checks for a QUIT event
    process_events(state)

    # moves the ball and paddles, updates scores, etc.
    update_game(state)

    # clears the old state from the display and draws the current state onto it
    draw_game(state)

    pygame.display.update()
    clock.tick(50)

And then separately implement all three of those functions, thinking
only about how each function needs to interact with the state and what
pygame calls it needs to make in order to accomplish its specific
task.  Right now the state object would only contain your paddle_rect,
but later you will presumably have more state to add (e.g. the
players' scores, the position and velocity of the ball, etc.), so it
will be useful then to have a single object you can pass around to
contain those.

[toc] | [prev] | [next] | [standalone]


#41154

FromAlex Gardner <agardner210@gmail.com>
Date2013-03-12 16:33 -0700
Message-ID<f4a50ed7-bf5c-4214-9a99-42fddaf3a4e4@googlegroups.com>
In reply to#40382
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@gmail.com)

Sorry but im back to square one.  My paddle isn't showing up at all! http://pastebin.com/PB5L8Th0

[toc] | [prev] | [next] | [standalone]


#41231

FromIan Kelly <ian.g.kelly@gmail.com>
Date2013-03-12 21:00 -0600
Message-ID<mailman.3311.1363271703.2939.python-list@python.org>
In reply to#41154
On Tue, Mar 12, 2013 at 5:33 PM, Alex Gardner <agardner210@gmail.com> wrote:
> Sorry but im back to square one.  My paddle isn't showing up at all! http://pastebin.com/PB5L8Th0

    paddle_rect.center = pygame.mouse.get_pos()

This updates the paddle position.

    screen.blit(beeper, paddle_rect)

This draws the paddle at that position.

    screen.blit(bpaddle, paddle_rect)

This draws the blank paddle at that same position.  Try to think about
why this results in the paddle not showing up.

If this is for a class, I think you should spend some quality time
with the TA rather than continue to throw non-functional code at this
list, which is clearly getting you nowhere.

[toc] | [prev] | [next] | [standalone]


#41242

FromAlex Gardner <agardner210@gmail.com>
Date2013-03-14 15:16 -0700
Message-ID<a12e33b7-414d-4207-8acd-f1f69b3d60a6@googlegroups.com>
In reply to#40382
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@gmail.com)

It's all working now with one exception.  I just want to arrange the paddle to the right side.  I managed to do just that, but it won't move freely vertically.  I am not fully aware of the arguments of pygame.Rect().  Here is what I am using:


bounds_rect = pygame.Rect(880,200,0,500)


Again, it all works minus the vertcal movement.  The full code (keep in mind it works fine now) is http://pastebin.com/xAAda30e

I thank you all (esp. Ian) for this help.  I broke down and remade the code and behold it works (with this exception).  Oh, Ian, this isn't a class assignment; it's a personal project to help me in the process of learning python.

[toc] | [prev] | [next] | [standalone]


#41245

FromIan Kelly <ian.g.kelly@gmail.com>
Date2013-03-14 16:31 -0600
Message-ID<mailman.3323.1363300329.2939.python-list@python.org>
In reply to#41242
On Thu, Mar 14, 2013 at 4:16 PM, Alex Gardner <agardner210@gmail.com> wrote:
> It's all working now with one exception.  I just want to arrange the paddle to the right side.  I managed to do just that, but it won't move freely vertically.  I am not fully aware of the arguments of pygame.Rect().

I recommend you read the docs, then:

http://www.pygame.org/docs/ref/rect.html

In particular, the clamp method documentation states:

        If the rectangle is too large to fit inside, it is centered
        inside the argument Rect, but its size is not changed.

This is the case because your bounds_rect has width 0.  I suggest
changing the width of the bounds_rect to be equal to the width of the
paddle.

[toc] | [prev] | [next] | [standalone]


#41247

FromAlex Gardner <agardner210@gmail.com>
Date2013-03-14 15:56 -0700
Message-ID<586f74eb-aa7d-4859-91d8-4e21f91f4c61@googlegroups.com>
In reply to#40382
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@gmail.com)

The docs helped (never knew they were there!) and its all safe and sound for now.   Thanks :)

[toc] | [prev] | [next] | [standalone]


#41457

FromAlex Gardner <agardner210@gmail.com>
Date2013-03-18 13:24 -0700
Message-ID<eaa2e236-002e-465b-a5c0-0c707bbb32c1@googlegroups.com>
In reply to#40382
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@gmail.com)

All is okay save for one thing!  I joined the ball and the p1 paddle in the same program.  Both of the images flicker to some extent.  The paddle itself rarely shows up.  I am not quite sure where / when to flip the display :(

[ http://pastebin.com/xzMwa85X ]

[toc] | [prev] | [next] | [standalone]


#41464

FromAlex Gardner <agardner210@gmail.com>
Date2013-03-18 16:05 -0700
Message-ID<96cd9bcb-e510-4d43-a597-fc4e84e62b7a@googlegroups.com>
In reply to#41457
On Monday, March 18, 2013 3:24:57 PM UTC-5, Alex Gardner 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@gmail.com)
> 
> 
 
 All is okay save for one thing!  I joined the ball and the p1 paddle in the same program.  Both of the images flicker to some extent.  The paddle itself rarely shows up.  I am not quite sure where / when to flip the display :(
 
 
 
 [ http://pastebin.com/i1GbT6JB ]

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web