I searched previously and found a thread on culling off screen sprites for 
better performance. In the end, the guy suggested to simply set a sprites 
visible flag.

However, I have tried this and the performance is abysmal, making the game 
unplayable.

Here is my code:

class TileLayer(object):
    def __init__(self):
        self.group = pyglet.graphics.Group()
        self.batch = pyglet.graphics.Batch()
        self.sprites = []
        self.cache = {}
        
    def setInViewSprites(self):
        """ Called everytime the camera bounds change, cache which sprites 
are in view and not in view, then change visibility """
        bounds = viewService.getScreenBounds()

        if not bounds in self.cache:
            inViewSprites = []

            for sprite in viewService.collideView(self.sprites):
                inViewSprites.append(sprite)
            
            self.cache[bounds] = inViewSprites

        for sprite in self.sprites:
            if not sprite in self.cache[bounds]:
                if sprite.visible == True:
                    sprite.visible = False
            else:
                if sprite.visible == False:
                    sprite.visible = True


This seems super inefficient to me, but I can't think of any other way. In 
another library I could simply just keep a list of sprites in and out of 
view, and pass the list to the renderer for easy and quick removal of 
sprites.

However because of batching and groups, this doesn't seem possible. Any 
suggestions?

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to