Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'position,': 0.04; 'mouse': 0.07; 'stops': 0.07; 'python': 0.09; '(0,': 0.09; 'cursor': 0.09; 'moving.': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr :python-list': 0.10; "wouldn't": 0.11; 'file,': 0.15; 'sat,': 0.15; '6:56': 0.16; 'docstring': 0.16; 'ian.': 0.16; 'invisible': 0.16; 'observations': 0.16; 'pygame': 0.16; 'subject:Pygame': 0.16; 'true:': 0.16; 'wrote:': 0.17; 'alex': 0.17; 'module': 0.19; 'clock': 0.22; 'finally,': 0.22; 'cc:2**0': 0.23; 'second': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'appear': 0.26; 'instead.': 0.27; 'library.': 0.27; 'subject:/': 0.28; 'cpu': 0.29; 'loop,': 0.29; 'second,': 0.29; 'sleep': 0.29; 'thus,': 0.29; 'probably': 0.29; 'this.': 0.29; "i'm": 0.29; 'position.': 0.30; 'code': 0.31; 'problem.': 0.32; 'generally': 0.32; 'idle': 0.33; 'turns': 0.33; 'problem': 0.33; 'code:': 0.33; 'received:google.com': 0.34; 'screen': 0.34; 'replaced': 0.35; 'doing': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'next': 0.35; 'explain': 0.36; 'anything': 0.36; 'thank': 0.36; 'skip:p 20': 0.36; 'enough': 0.36; 'does': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'instead': 0.39; 'help': 0.40; 'end': 0.40; 'think': 0.40; 'your': 0.60; 'first': 0.61; 'times': 0.63; 'more': 0.63; 'making': 0.64; 'here': 0.65; 'learned': 0.65; 'useful.': 0.65; 'soon': 0.70; '2013': 0.84; 'much,': 0.84; 'replacements': 0.84; 'draws': 0.91 X-Received: by 10.49.24.164 with SMTP id v4mr1688072qef.6.1362282720480; Sat, 02 Mar 2013 19:52:00 -0800 (PST) Newsgroups: comp.lang.python Date: Sat, 2 Mar 2013 19:52:00 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=108.95.20.220; posting-account=kGHztQoAAABWYt08oBIrT5-Wm777e-qb References: User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 108.95.20.220 MIME-Version: 1.0 Subject: Re: Pygame mouse cursor load/unload From: Alex Gardner To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Python X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 97 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362282722 news.xs4all.nl 6930 [2001:888:2000:d::a6]:55567 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40397 On Saturday, March 2, 2013 9:08:18 PM UTC-6, Ian wrote: > On Sat, Mar 2, 2013 at 6:56 PM, Alex Gardner wrot= e: >=20 > > I am in the process of making a pong game in python using the pygame li= brary. My current problem is that when I move the mouse, it turns off as s= oon as the mouse stops moving. The way I am doing this is by making the de= fault 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 w= ay that I can. Here are the links that contain my code: >=20 >=20 >=20 > Your mouse motion code draws the paddle in the new position, waits >=20 > 1/10th of a second, and then draws over it again with the "invisible" >=20 > paddle. Thus, approximately 1/10th of a second after you stop moving >=20 > the mouse, it disappears. >=20 >=20 >=20 > Mouse motion events are probably not the best way to do this. You can >=20 > instead just capture the current position of the mouse on every frame >=20 > and use that instead. I replaced your main loop with the following: >=20 >=20 >=20 > paddle_pos =3D (0, 0) >=20 > clock =3D pygame.time.Clock() >=20 >=20 >=20 > while True: >=20 > for event in pygame.event.get(): >=20 > if event.type =3D=3D QUIT: >=20 > sys.exit() >=20 >=20 >=20 > # Erase the paddle from the old mouse position. >=20 > screen.blit(bpaddle, paddle_pos) >=20 > # Redraw the net before the paddle so that the paddle can appear over= it. >=20 > pygame.draw.line(screen, game.lineColor, game.net1, game.net2, >=20 > game.netWidth) >=20 > # Get the new mouse position. >=20 > paddle_pos =3D pygame.mouse.get_pos() >=20 > # Draw the paddle at the new mouse position. >=20 > screen.blit(beeper, paddle_pos) >=20 > # Update the screen if it's double-buffered. >=20 > pygame.display.update() >=20 > # Finally, let the CPU idle until it's time for the next frame. >=20 > # 50 here means that it will sleep long enough to achieve 50 FPS. >=20 > clock.tick(50) >=20 >=20 >=20 > And I think you will find that this does what you want. >=20 >=20 >=20 > A couple more observations while I'm at it. Generally there is no >=20 > need to be calling pygame.display.update() multiple times per frame. >=20 > Just draw everything that you need, and then call it once at the end >=20 > of the loop, as I have shown above. Also, the shebang line only does >=20 > anything if it's the very first line in the file, so it would need to >=20 > 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 le= arning as I go with this project. Again, thank you :)