cocos.batch module

Batch

Batches

Batches allow you to optimize the number of gl calls using pyglets batch

class BatchNode

Bases: cocos.cocosnode.CocosNode

add(child, z=0, name=None)

Adds a child and if it becomes part of the active scene, it calls its on_enter() method.

Parameters
  • child (CocosNode) – object to be added

  • z (Optional[float]) – the child z index. Defaults to 0.

  • name (Optional[str]) – Name of the child. Defaults to None

Returns

CocosNode – self

draw()

This is the function you will have to override if you want your subclassed CocosNode to draw something on screen.

You must respect the position, scale, rotation and anchor attributes. If you want OpenGL to do the scaling for you, you can:

def draw(self):
    glPushMatrix()
    self.transform()
    # ... draw ..
    glPopMatrix()
remove(child)

Removes a child given its name or object

If the node was added with name, it is better to remove by name, else the name will be unavailable for further adds (and will raise an Exception if add with this same name is attempted)

If the node was part of the active scene, its on_exit() method will be called.

Parameters

obj (str or object) – Name of the reference to be removed or object to be removed.

visit()

All children are placed in to self.batch, so nothing to visit

class BatchableNode

Bases: cocos.cocosnode.CocosNode

add(child, z=0, name=None)

Adds a child and if it becomes part of the active scene, it calls its on_enter() method.

Parameters
  • child (CocosNode) – object to be added

  • z (Optional[float]) – the child z index. Defaults to 0.

  • name (Optional[str]) – Name of the child. Defaults to None

Returns

CocosNode – self

remove(child)

Removes a child given its name or object

If the node was added with name, it is better to remove by name, else the name will be unavailable for further adds (and will raise an Exception if add with this same name is attempted)

If the node was part of the active scene, its on_exit() method will be called.

Parameters

obj (str or object) – Name of the reference to be removed or object to be removed.

set_batch(batch, groups=None, z=0)