On Tue, Jun 12, 2012 at 5:22 PM, Nitneroc <[email protected]> wrote:
> I reused your code, claudio, because I'm having fun with a grid-based game > where some cells can be filled with water at different levels. > My problem is that I will display many of those (in a big grid) and want > them to be batchable. I'm sorry but I can't find any help on how to make > something batchable. > > here is a crude attempt : http://pastebin.com/7FYWrDA6 > The water_block will not be displayed if added to a BatchNode, but will be > displayed ok when added to a regular Node... > > Could someone enlighten me ? > > Sorry if this will come too concise, but here we go: Pyglet batchs groups a bunch of vertexes to draw them in a single call. Your code is must update vertex coordinates, and the vertex coordinates should be in the same coordinate system. In cocos three ways to use batches can be seen: + The tilemap way: have a private batch that uses a bunch of sprites. Look at cocos.tiles class MapLayer. Here updating vertex lists is done by manipulating the sprites + The ColorLayer way: have a private batch and maintain directly the vertex list. + The cocos.draw way: have one BatchNode which holds a pyglet batch and many childs that are BatchableNodes ; each child updates only a subset of vertex list, the vertexes should be in BatchNode coordinates. IOW, to update vertex list a BatchNode should consider position, rotation, scale. Designing to have rotation=0 and scale=1 simplifies things. If position in the parent BatchNode coordinates, as usually in grids, dont change after creation, then providing vertexes is too much complicated. Going to your code, you are trying to mix approach 2 and 3, and that does not work. I pasted an incomplete batched implementation in the third style that may help you: http://pastebin.com/Uh1uVDg3 Look at the big description there for some ideas. claudio -- -- 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.
