On Thu, Nov 26, 2009 at 3:25 PM, flx <[email protected]> wrote: > On Nov 25, 6:42 pm, flx <[email protected]> wrote: > > I've been trying a litle cocos2d and I'm loving it, but I've found > > that sprites seems to be drawing even if they're not inside the > > visible area of a layer. How can i prevent them from update or draw if > > they're outside the viewport? > > > > Here is some test code i was trying with, i'm sure that i've been > > doing things the wrong way so help's apreciated. > > > > -- > > > > import sys > > import os > > sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) > > > > import cocos > > from cocos.actions import * > > > > class TLayer(cocos.layer.Layer): > > is_event_handler = True > > def __init__(self): > > cocos.layer.Layer.__init__(self) > > self.sprites = [] > > for i in range(1000): > > s = cocos.sprite.Sprite('fire.png', (100 * i, 100 * i)) > > self.sprites + [s] > > self.add(s); > > > > def on_mouse_scroll(self, x, y, dx, dy): > > self.do(ScaleBy(0.25 * dy + 1.0, 0.5)) > > > > def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers): > > self.x += dx > > self.y += dy > > > > if __name__ == "__main__": > > cocos.director.director.init(vsync=True) > > cocos.director.director.show_FPS=True > > > > layer = TLayer() > > > > cocos.director.director.run (cocos.scene.Scene(layer)) > > In the test only 3 or 4 images should be rendered, but it runs at > ~3fps no matter how many images are displayed > > Btw, is there someone still using this framework? it seems that only > the iphone version is active :( > > -- >
Theres no specific cocos way to spare the unneeded draws. I think (but not sure) pyglet does not have an automatic thing to handle this. The basics would be to split the geometry in some big groups for which is cheap to answer: any sprite in this group needs drawing ? This is the part that you need to grow. I suspect this optimization depends heavily on the particular application, like: immobile sprites ? -> preclasiffy in some suitable rects, at run time use the rect to decide if it can be discarded mobiles but clustered around some points (particle like, maybe) ? -> take a circle or rect around a congregation point, intersect with camera to know if the group can be discarded. You can try to google for 'opengl potentially visible' for other approachs, or translate the example to pure pyglet and ask in pyglet list for suggestions. Then you draw only the potentially visible groups, probably using the group keyword param in sprites (see batchs in pyglet docs). Yes, the framework is in use, mostly at pyweek time, albeit the devs seems to be focusing in other projects at this time. -- claxo -- You received this message because you are subscribed to the Google Groups "cocos2d discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/cocos-discuss?hl=en.
