Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.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.069 X-Spam-Evidence: '*H*': 0.86; '*S*': 0.00; 'block.': 0.09; 'logic': 0.09; 'entirely.': 0.16; 'pygame': 0.16; 'range,': 0.16; 'subject:Pygame': 0.16; 'wrote:': 0.17; 'alex': 0.17; 'skip:p 30': 0.20; 'header:In-Reply-To:1': 0.25; 'updating': 0.27; 'replace': 0.27; 'message-id:@mail.gmail.com': 0.27; 'subject:/': 0.28; 'falls': 0.29; 'class': 0.29; 'code': 0.31; 'to:addr:python-list': 0.33; 'code:': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; "won't": 0.35; 'received:209.85': 0.35; 'problems': 0.36; 'skip:p 20': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'your': 0.60; 'range': 0.60; 'you.': 0.61; 'solve': 0.62; '2013': 0.84; 'to:name:python': 0.84; 'updated,': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=RmouYfSrTwGrrNTT3Vp6Tj/Y+JHCwtMcTpEKLEZ1FQg=; b=C2NV/02QKscWZ2cwdlFGcggnPxhs7Gk43nExWS38NDZknb8/AyBE+YmFSkNS5zXR+o eDJjQ7LCBBmdLDCZ4lqfNqmAF5LgGjyySAqTTbVOUyDBeCS8tuTzmg/K2CIl1+FPv9ER /NO9JJb2vfpUhM7hbATBySKWvpxIrwytGGU4HG6ZUgyrcYOyKyFqt1fE96XCbESLm3di F9Owg4A/2yC5ZSM8a/K56YG7yzY21VY+mNlpuZu8zZ41b3zv3FSQFCuyX9sz1hQ6dUzG EgGrqS7rJuiyXtsyGAwV1ra9jPxggfYa9ywIZkj1l93wmVlO3uDTfGyvdaEs0Ak46da2 wjVA== X-Received: by 10.52.177.163 with SMTP id cr3mr6084369vdc.94.1362354468556; Sun, 03 Mar 2013 15:47:48 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <9c352284-08c4-439e-b324-caffa3718429@googlegroups.com> References: <9c352284-08c4-439e-b324-caffa3718429@googlegroups.com> From: Ian Kelly Date: Sun, 3 Mar 2013 16:47:08 -0700 Subject: Re: Pygame mouse cursor load/unload To: Python Content-Type: text/plain; charset=ISO-8859-1 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: , Newsgroups: comp.lang.python Message-ID: Lines: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362354471 news.xs4all.nl 6867 [2001:888:2000:d::a6]:37735 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40430 On Sun, Mar 3, 2013 at 3:09 PM, Alex Gardner wrote: > if (0,0) <= paddle_pos <= (300,300): This doesn't do what you think it does. Tuples are compared lexicographically, not element-wise. So (250, 350) < (300, 300), but (350, 250) > (300, 300). > paddle_pos = pygame.mouse.get_pos() > screen.blit(beeper, paddle_pos) > pygame.display.update() > clock.tick(50) You're updating paddle_pos inside the if block. Once paddle_pos falls outside that range, the if block won't trigger, and paddle_pos will no longer be updated, so it will never fall inside that range again. pygame has a Rect class for rectangle logic that can solve both of these problems for you. Given: paddle_rect = beeper.get_rect() bounds_rect = pygame.Rect(0, 0, 300, 300) your position update code then becomes: paddle_rect.center = pygame.mouse.get_pos() paddle_rect.clamp_ip(bounds_rect) Note that paddle_rect can replace paddle_pos entirely. The code: screen.blit(beeper, paddle_pos) simply becomes: screen.blit(beeper, paddle_rect)