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

[pygame] Re: Sprite group drawing with offset

Oops. I forgot to attach mine.

Also, the idea would be to have the offset having a default value, so
code that uses the current sprite code still works after updating.


On Tue, Mar 10, 2009 at 11:15 PM, Thiago Chaves <shundread@xxxxxxxxx> wrote:
> 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
    def update(self, screenRect, world, inputObjects, time):
        '''Takes as parameters:
        screenRect:   The screen's rectangle in relation to the map's (0,0)
        world:        The collection of game objects, map information, etc.
        inputObjects: Input objects. It may be reading information from one of
        time:         Time passed since last update call.'''
        self.rect.left = self.position[0] - screenRect.left
        self.rect.top  = self.position[1] - screenRect.top