batches and text

14 views
Skip to first unread message

Nitneroc

unread,
Apr 16, 2012, 2:50:51 PM4/16/12
to cocos-...@googlegroups.com
As I said in another thread, I'm a newbie, so I hope my question isn't totally stupid.

I have Sprite objects, with a name displayed above them. This name is a cocos2d Label. For speed-ups, I wanted to put the Sprites in a batch, so I just tried to add them as children to the BatchNode. This raised an error because the Label isn't a BatchableNode. I knew things couldn't be that easy, but I tried to create my own Label class that inherited from BatchableNode, and the exception disappeared, but there is only one of my labels displayed, and I don't really understand how to make it work...

In fact I don't know a thing about how batches manage to speed-up drawing operations, I guess it's by calling draw for objects with the same graphics. So I guess putting text inside a batch is meaningless (looking through cocos.text.TextElement, I think I understood that pyglet uses a specific batch for each label).

How can I add such a Sprite to a BatchNode ?

Thanks for reading

claudio canepa

unread,
Apr 17, 2012, 12:11:07 AM4/17/12
to cocos-...@googlegroups.com
On Mon, Apr 16, 2012 at 3:50 PM, Nitneroc <corent...@gmail.com> wrote:
As I said in another thread, I'm a newbie, so I hope my question isn't totally stupid.

I have Sprite objects, with a name displayed above them. This name is a cocos2d Label. For speed-ups, I wanted to put the Sprites in a batch, so I just tried to add them as children to the BatchNode. This raised an error because the Label isn't a BatchableNode. I knew things couldn't be that easy, but I tried to create my own Label class that inherited from BatchableNode, and the exception disappeared, but there is only one of my labels displayed, and I don't really understand how to make it work...

In fact I don't know a thing about how batches manage to speed-up drawing operations, I guess it's by calling draw for objects with the same graphics.

No, batches speed-up comes from drawing as many vertexs in as few calls to openGL as possible, and minimizing the number of openGL state changes.

For a 10000ft overview see
 
To know more you will need to read the related pyglet code and be familiar with  
openGL.

So I guess putting text inside a batch is meaningless (looking through cocos.text.TextElement, I think I understood that pyglet uses a specific batch for each label).

How can I add such a Sprite to a BatchNode ?


Forget batches while being new to cocos-pyglet.

Make a simple NamedSprite, beginning with something like

class NamedSprite(cocos.cocosnode.CocosNode):
    def __init__(self, name, *args, **kwargs):
        self.figure = cocos.sprite.Sprite(*args, **kwargs)
        self.label = cocos.text.Label(name)
        # adjust label position
        self.add(self.figure)
        self.add(self.label)
 
hth

claudio

--

Nitneroc

unread,
Apr 17, 2012, 7:05:59 AM4/17/12
to cocos-...@googlegroups.com
OK I looked at this pyglet documentation and I didn't understand much of it... So I'll follow your advice and stick to the no-batch option, with a class pretty similar to yours.

Thanks for the kind explanations
Reply all
Reply to author
Forward
0 new messages