pymunk.pyglet_util Module

This submodule contains helper functions to help with quick prototyping using pymunk together with pyglet.

Intended to help with debugging and prototyping, not for actual production use in a full application. The methods contained in this module is opinionated about your coordinate system and not very optimized (they use batched drawing, but there is probably room for optimizations still).

pymunk.pyglet_util.draw(*objs, **kwargs)[source]

Draw one or many pymunk objects. It is perfectly fine to pass in a whole Space object.

Objects that can be handled are:
  • pymunk.Space
  • pymunk.Segment
  • pymunk.Circle
  • pymunk.Poly

If a Space is passed in all shapes in that space will be drawn. Unrecognized objects will be ignored (for example if you pass in a constraint).

Typical usage:

>>> pymunk.pyglet_util.draw(my_space)

You can control the color of a Shape by setting shape.color to the color you want it drawn in.

>>> my_shape.color = (255, 0, 0) # will draw my_shape in red

If you do not want a shape to be drawn, set shape.ignore_draw to True.

>>> my_shape.ignore_draw = True

(However, if you want to ignore most shapes its probably more performant to only pass in those shapes that you want to be drawn to the draw method)

You can optionally pass in a batch to use. Just remember that you need to call draw yourself.

>>> pymunk.pyglet_util.draw(my_shape, batch = my_batch)
>>> my_batch.draw()

See pyglet_util.demo.py for a full example

Param :
objs : One or many objects to draw.

Can be either a single object or a list like container with objects.

kwargs : You can optionally pass in a pyglet.graphics.Batch

If a batch is given all drawing will use this batch to draw on. If no batch is given a a new batch will be used for the drawing. Remember that if you pass in your own batch you need to call draw on it yourself.