sprite shapes -- adding points procedurally

Hey all,

I’m trying to add points to a sprite shape in the form of a procedurally generated circle like this:

 public void AddNode(GameObject node)
    {
        node.transform.SetParent(this.transform);
        SpriteShape.spline.InsertPointAt(points.Count, node.transform.localPosition);
        points.Add(node.transform);
        SpriteShape.spline.SetTangentMode(points.Count - 1, ShapeTangentMode.Continuous);
        SpringJoint2D sj = node.GetComponent<SpringJoint2D>();
        sj.connectedBody = _rb;
    }

,but the circle somehow keeps being inverted. Like this – the border is on the inside, and the fill is on the outside:

Yes, for those who recognize it, this is the open source CellCraft project that I’m porting from Flash to Unity. Getting the membrane right is the hardest task to date. The texture I’m using is just a 100x100 square with the border at the top.

When I enter the points manually and drag them around, it looks fine:

Any explanation/fix, from Sprite Shape experts? This really needs to be done procedurally, as the circle size needs to vary and change during gameplay.

EDIT: To forestall comments about open-endedness – I only turned that on in image 1 for the purpose of showing you the texture without the fill. When the shape is closed, it looks the same, with extra filling in the middle – the border is still on the inside.

What happens if you wind the circle the other way around?

2 Likes

Thanks, that worked, as did inverting the heights to -1 (though your solution makes more sense). Weird – I did not realize the order in which the points were added to their respective transforms would determine which way the shape sprites were facing.

I was just guessing, but this is fairly common construct in geometry-related coding (in and out of Unity), used in things such as vertex winding order, left/right side of a LineRenderer or TrailRenderer, etc., so it does not surprise me that Sprite Shapes do it too.