[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] Sprite group drawing with offset
- To: pygame-users@xxxxxxxx
- Subject: [pygame] Sprite group drawing with offset
- From: Thiago Chaves <shundread@xxxxxxxxx>
- Date: Tue, 10 Mar 2009 23:15:46 +0200
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Tue, 10 Mar 2009 17:15:55 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=kYAZW6sb7yfUdaHHMhB9eGmd3kKQtzE7OAZsIIAW4Zg=; b=C+o8lUyJ1TXK8ZR1W2kx4NpZmFLe07SRf5tD2XzMUpWsQin+EBnvwc5/+MCKC5gNzQ OrQBHL2t8ARby7R7BvKwaxd6VkRjrI8FfchLGF5gqRccKFb0JQxKT1iE1A8J3kiWDDTt 2u6Qqi0X+TxRTJ1IecPv+kUvhtN8nXm172tXo=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=AV3cLFD6MKZr98vNNlojrjrNzcQT0YV4k4mxYkki9PvcFypBwuJX9EC5C0SG3s4uOx g3rEkU8Vd9xsBXoq/VVA4b22da2jhZZDdwnq07FiQFQWtU52ytuFxjVVAequbsdj92jA RBriHDbU34rN5ORXWa1pRTlO5W5BS3JSQCCsw=
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Hi,
I just had a conversation with some people at #pygame on IRC, and it
seems that at least me and unlucky777 agree that it would be cool to
be able to pass an offset value to the drawing function on pygame
sprite groups. The idea is that people who think about a "camera" (or
when writing games have something more natural to work with).
Anyway, unlucky777 came up wth some modified renderUpdates sprite
group to solve a scrolling problem, while I caught myself putting
offset information on the update method of my sprite classes so I
could deal with the same problem (but apparently in an uglier way).
I'm attaching unlycky777's relevant piece of code, and also what I
came up with. Personally, I like unlucky's idea better.
Any thoughts?
-Thiago
#from the sprite (module?) class RenderUpdates(Group):
def draw(self, surface, offset):
spritedict = self.spritedict
surface_blit = surface.blit
dirty = self.lostsprites
self.lostsprites = []
dirty_append = dirty.append
for s in self.sprites():
r = spritedict[s]
newrect = surface_blit(s.image, s.rect.move(offset))
if r is 0:
dirty_append(newrect)
else:
if newrect.colliderect(r):
dirty_append(newrect.union(r))
else:
dirty_append(newrect)
dirty_append(r)
spritedict[s] = newrect
return dirty