[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Paralax snow flaks: Some tipps for enhancing the performance?



Ok, I corrected that! But now another error occures:

File "schneeflocken_dirty_rects.py", line 93, in ?
main()
File "schneeflocken_dirty_rects.py", line 74, in main
screen.blit(background, dirty, dirty)
TypeError: invalid destination position for blit

Hmm, th thought that it was obvious, that "dirty, dirty" wasn't a valid destination for to blit sth.
So I changed

for i in dirty:
screen.blit(background,dirty, dirty)
old_dirty = dirty
dirty = []

to

for i in dirty:
screen.blit(background,dirty.get_abs_offset(),dirty.get_rect())
old_dirty = dirty
dirty = []


But now I get this:

Traceback (most recent call last):
File "schneeflocken_dirty_rects.py", line 93, in ?
main()
File "schneeflocken_dirty_rects.py", line 74, in main
screen.blit(background,dirty.get_abs_offset(),dirty.get_rect())
AttributeError: 'list' object has no attribute 'get_abs_offset'

Sorry for the stupied Newbie Questions....

thanks, Ludwig


Am Dienstag, 04.05.04, um 00:31 Uhr (Europe/Berlin) schrieb Ian Sharkey:

Just one little correction. Technically, 'dirty' does contain a value at that for loop, however, the interpreter believes that 'dirty' is a local variable, separate from the globally defined one.

Whenever an assignment to a variable takes place in a function, the interpreter assumes that it is local, even if there is a global variable that has the same name (and even if there is references to the value that do _not_ write to it).

Changing main() like so:

def main():
global dirty # reference the global dirty variable
frames=0
... #etc

should do the trick.

- Ian

From: Ricardo Jamin <ricardo@jaminphotography.com>
Reply-To: pygame-users@seul.org
To: pygame-users@seul.org
Subject: Re: [pygame] Paralax snow flaks: Some tipps for enhancing the performance?
Date: 3 May 2004 12:06:26 -0000



You guessed it right.
the first time you call dirty in the main()
is in that for loop. So there\'s no value in the variable yet, not even None.

By mischance the Interpreter splits out this:


File \"schneeflocken_dirty_rects.py\", line 69, in main
for i in dirty:
UnboundLocalError: local variable \'dirty\' referenced before assignment

Hmm, i don\'t really understand this error message. It means something like \"want\'s to deal with a variable which hasn\'t been declared yet\" ??? Hmm, i think will toy around with this problem a little bit!

greets, Ludwig
_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN Premium http://join.msn.com/?pgmarket=en-ca&page=byoa/ prem&xAPID=1994&DI=1034&SU=http://hotmail.com/ enca&HL=Market_MSNIS_Taglines