3

I am trying to create shapes using pymunk with pyglet. But I am facing a problem that I unable to change the color of a pymunk shape. They don't have any such attribute.

I have tried draw_polygon in pymunk.pyglet_utils.DrawOptions but there were no results. What are they for?

I_love_vegetables
  • 1,575
  • 5
  • 12
  • 26
Xavier
  • 39
  • 2

1 Answers1

4

The color attribute does not exist from the start, but you can still set it.

This small snippet sets the color to red for example.

import pymunk
import pymunk.pygame_util

space = pymunk.Space()
options = pymunk.pyglet_util.DrawOptions()

body = pymunk.Body(1, 10)
shape = pymunk.Circle(body, 10)
shape.color = (255, 0, 0, 255) # will draw my_shape in red
space.add(body, shape)

space.debug_draw(options)

See http://www.pymunk.org/en/latest/pymunk.pyglet_util.html#pymunk.pyglet_util.DrawOptions.init

viblo
  • 4,159
  • 4
  • 20
  • 28