[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Fwd: [Tutor] A more Pythonic way to do this
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Fwd: [Tutor] A more Pythonic way to do this
- From: "D. Hartley" <denise.hartley@xxxxxxxxx>
- Date: Wed, 6 Jul 2005 10:24:22 -0700
- Delivered-to: archiver@seul.org
- Delivered-to: pygame-users-outgoing@seul.org
- Delivered-to: pygame-users@seul.org
- Delivery-date: Wed, 06 Jul 2005 13:24:35 -0400
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=qL4gvs/XG3Ft3uoFoWKEV7wr/aIvcym67iQ8FR49ep0QeJy4J+8FD4i4uQgLeYcgdLx0IAQcs2ZTC8fSG1+lqWKKF/XWah4J0YgIZG6Z+UMxygQgMCxB62dIkuOhgH2oVbUE8faD8T79p1QndGy4qo8TJm2ntovqx+zENddwhII=
- In-reply-to: <Pine.LNX.4.56.0507052116290.29518@twobox.geeky.net>
- References: <8daabe5605063015111d32477a@mail.gmail.com> <42C5B888.6000708@po-box.mcgill.ca> <8daabe5605070115567afb6c39@mail.gmail.com> <42C5CC7D.4070705@po-box.mcgill.ca> <8daabe5605070117216b20c08a@mail.gmail.com> <be4fbf9205070206397f35dfed@mail.gmail.com> <8daabe56050705115964075b58@mail.gmail.com> <be4fbf9205070515584d510fd9@mail.gmail.com> <8daabe5605070516351857d85e@mail.gmail.com> <Pine.LNX.4.56.0507052116290.29518@twobox.geeky.net>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
> The symptom is that they are all painting on top of each other in the same
> position. Correct?
You got it.
> The confusion here is between *class* attributes and *object* attributes
> (or more pythonically speaking, *instance* attributes).
....*snip*...
> class Enemy:
> someVar = 90
> def __init__(self):
> self.pants = 44
>
> We usually just call "pants" an attribute, but we usually give special
> significance to "someVar" and call it a "class attribute" -- it is common
> across all instances of that class
...*snip*...
> Anyway enough lecturing. The basic rule is stay away from class
> attributes unless you need them. Just use instance attributes by defining
> attributes in your __init__() function, like "pants" above.
Ok, so I set up, within my Enemy class, the following:
class Enemy(pygame.sprite.Sprite):
def __init__(self, startx, starty, level):
pygame.sprite.Sprite.__init__(self)
*snip*
self.rect.centerx = startx
self.rect.centery = starty
self.initialx = 0
self.initialy = 0
so.... didn't I set it up as an instance attribute and NOT as a class
attribute? each new "self" should have its own initialx, initialy,
right? Or am I misunderstanding you?
~Denise