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


Groups > comp.lang.python > #40396

Re: Pygame mouse cursor load/unload

Newsgroups comp.lang.python
Date 2013-03-02 19:52 -0800
References <d6374016-8863-4e8b-9ec9-17a826ca2eee@googlegroups.com> <mailman.2809.1362280147.2939.python-list@python.org>
Message-ID <4010f9c7-7a1a-4168-ac32-841d7d8ba486@googlegroups.com> (permalink)
Subject Re: Pygame mouse cursor load/unload
From Alex Gardner <agardner210@gmail.com>

Show all headers | View raw


On Saturday, March 2, 2013 9:08:18 PM UTC-6, Ian wrote:
> On Sat, Mar 2, 2013 at 6:56 PM, Alex Gardner <agardner210@gmail.com> 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:
> 
> 
> 
> Your mouse motion code draws the paddle in the new position, waits
> 
> 1/10th of a second, and then draws over it again with the "invisible"
> 
> paddle.  Thus, approximately 1/10th of a second after you stop moving
> 
> the mouse, it disappears.
> 
> 
> 
> Mouse motion events are probably not the best way to do this.  You can
> 
> instead just capture the current position of the mouse on every frame
> 
> and use that instead.  I replaced your main loop with the following:
> 
> 
> 
> paddle_pos = (0, 0)
> 
> clock = pygame.time.Clock()
> 
> 
> 
> while True:
> 
>     for event in pygame.event.get():
> 
>         if event.type == QUIT:
> 
>             sys.exit()
> 
> 
> 
>     # Erase the paddle from the old mouse position.
> 
>     screen.blit(bpaddle, paddle_pos)
> 
>     # Redraw the net before the paddle so that the paddle can appear over it.
> 
>     pygame.draw.line(screen, game.lineColor, game.net1, game.net2,
> 
>                      game.netWidth)
> 
>     # Get the new mouse position.
> 
>     paddle_pos = pygame.mouse.get_pos()
> 
>     # Draw the paddle at the new mouse position.
> 
>     screen.blit(beeper, paddle_pos)
> 
>     # Update the screen if it's double-buffered.
> 
>     pygame.display.update()
> 
>     # Finally, let the CPU idle until it's time for the next frame.
> 
>     # 50 here means that it will sleep long enough to achieve 50 FPS.
> 
>     clock.tick(50)
> 
> 
> 
> And I think you will find that this does what you want.
> 
> 
> 
> A couple more observations while I'm at it.  Generally there is no
> 
> need to be calling pygame.display.update() multiple times per frame.
> 
> Just draw everything that you need, and then call it once at the end
> 
> of the loop, as I have shown above.  Also, the shebang line only does
> 
> anything if it's the very first line in the file, so it would need to
> 
> appear before the module docstring to do anything useful.

Thank you very much, Ian.  I understand the code and have learned from it.  If I were more knowledgeable in python I wouldn't have had to ask; I am learning as I go with this project.  Again, thank you :)

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web