Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circle and svg in one body #1293

Open
maketryuk opened this issue May 16, 2024 · 0 comments
Open

Circle and svg in one body #1293

maketryuk opened this issue May 16, 2024 · 0 comments

Comments

@maketryuk
Copy link

Hello everyone. I'm creating a body with two elements in it:

  1. The circle
  2. SVG element

The problem is that if I wrap it in body.create, the svg breaks completely. But if you add one svg not to the body, but immediately to the Composite, then everything works. But I definitely need to have a circle as well.

I will be glad to help.

The problem with body.create:
https://github.com/liabru/matter-js/assets/95985954/8a097c56-0e50-4c2e-b18a-f6ce331fd6e9

The problem with the lack of a circle:
https://github.com/liabru/matter-js/assets/95985954/df34b028-de0a-4c70-891a-e7f3c458dcc7

loadSvg(item).then((root) => {
    const vertexSets = select(root, "path").map(function (path) {
    return Vertices.scale(Svg.pathToVertices(path, 10), 1, 1);
});

const circleOptions = Bodies.circle(
    isMobile() ? circleOffsetXOptions.mobile(index) : circleOffsetXOptions.desktop(index),
    10,
    isMobile() ? circleRadiusOptions.mobile : circleRadiusOptions.desktop,
    {
        render: {
            fillStyle: "transparent",
            lineWidth: 1,
            strokeStyle: this._isDarkTheme ? "#2D3137" : "#3F4144",
        },
        label: "custom_circle",
    },
);

const svgOptions = Bodies.fromVertices(
    isMobile() ? circleOffsetXOptions.mobile(index) : circleOffsetXOptions.desktop(index),
    10,
    vertexSets,
    {
        render: {
            fillStyle: this._isDarkTheme ? "#2E3035" : "#3F4144",
            strokeStyle: this._isDarkTheme ? "#2D3137" : "#3F4144",
            lineWidth: 1,
        },
        label: "custom_svg",
    },
);

// It works, but I need a circle.
// Composite.add(this.engine.world, svgOptions);

// It doesn't work
const buildElement = Body.create({
    parts: [circleOptions, svgOptions],
    friction: 0.03,
    frictionAir: 0.00001,
    restitution: 0.05,
});

Composite.add(this.engine.world, buildElement);
});```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant