ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> pygame-users
pygame-users
[pygame] Compatitbility broken in Rect.collidedict
by Tim Ansell other posts by this author
Aug 6 2007 12:43AM messages near this date
Re: [pygame] [Pygame] Generating a map | [BUG] Re: [pygame] Compatitbility broken in Rect.collidedict
Hello,

It appears that the Rect.collidedict method has had quite a bit of
overhaul between pygame 1.7 and pygame 1.8.

Documentation for pygame 1.7
>  Rect.collidedict(dict if rectstyle keys) -> key/value pair find
>  overlapping rectangle in a dictionary
>  
>  Returns the key/value pair of the first rectangle key in the dict that
>  overlaps the base rectangle. Once an overlap is found, this will stop
>  checking the remaining list. If no overlap is found, it will return
>  None.
>  
>  Remember python dictionary keys must be immutable, Rects are not
>  immutable, so they cannot directly be, dictionary keys. You can
>  convert the Rect to a tuple with the tuple() builtin command.

Documentation for pygame 1.8
http://www.pygame.org/docs/ref/rect.html#Rect.collidedict

>  Returns the key and value of the first dictionary value that collides
>  with the Rect. If no collisions are found, None is returned. 
>  
>  Rect objects are not hashable and cannot be used as keys in a
>  dictionary, only as values. 

Both forms are actually quite useful for a number of different tasks.
Maybe you should have a 

Rect.collidedictkeys   <- Check against keys
Rect.collidedictvalues <- Check against values

and then map Rect.collidedict to the keys variety for backwards
compatibility?
 
Tim Ansell
---
http://blog.mithis.net/ - Mithro Rants about Stuff
http://www.thousandparsec.net/ - Conquer the Universe (and then some)
Thread:
Tim Ansell
renesd

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved