Jump to content

Add Physics editor vertices to scene with no sprite


adam_cousins
 Share

Recommended Posts

Hi, 

I am trying to add my vertices exported from Physics Editor but I just want the vertices added to my scene, there is no image or sprite. I have this working (albeit I think incorrectly) like this:

var paths =  this.cache.json.get('paths');
this.matter.add.sprite(255, 660, null, null, {shape: paths.pathBottom});

So I am putting null where there should be a reference to a spritesheet and sprite. This has the result of the little green rectangle appearing (because it can't find the image resource) (although I do get my custom shapes added)

I have been trying lots of things based on their examples but I can't figure out how to just add the vertices (maybe as a polygon?) but with no sprite or image. Can anyone help?

 

Many thanks

Adam

 

 

Link to comment
Share on other sites

Use this:

    /**
     * [description]
     *
     * @method Phaser.Physics.Matter.Factory#fromVertices
     * @since 3.0.0
     *
     * @param {number} x - [description]
     * @param {number} y - [description]
     * @param {array} vertexSets - [description]
     * @param {object} options - [description]
     * @param {boolean} flagInternal - [description]
     * @param {boolean} removeCollinear - [description]
     * @param {number} minimumArea - [description]
     *
     * @return {MatterJS.Body} A Matter JS Body.
     */
    fromVertices: function (x, y, vertexSets, options, flagInternal, removeCollinear, minimumArea)
    {
        var body = Bodies.fromVertices(x, y, vertexSets, options, flagInternal, removeCollinear, minimumArea);

        this.world.add(body);

        return body;
    },

You can access it via `this.matter.add.fromVertices` in any Scene.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...