Search code examples
javascriptcanvaspaperjs

In PaperJS is it possible to group several items together so they move as one?


I have a PaperJS project with lots of circles that can move independently. I also want each of these circles to have some PointText at their centre, like a label.

I don't want to animate each of the labels every time their parent circle moves though, I'd like for them to just move automatically whenever their parent circle moves. Is that possible, and how would I do that?


Solution

  • Look at the Group class.

    This would allow you to create multiple circle objects, say circle1 and circle2 and then group them like so:

    var group = new Group([circle1, circle2]);
    

    now you can perform transforms on the group

    group.position = view.center;