Jump to content

Dynamic Points for Ropes


DavidJAldred
 Share

Recommended Posts

Can anyone confirm that once a rope has been created it has a fixed amount of points, which cannot be altered? I know the positions of the points can be modified but does the array of points itself have a fixed length after it has been created?

If so, what would be the best way around this? Destroying the rope and creating a new one every time the number of points change? Or is there a way to only draw the rope between certain points in it's points array?

I'm looking for a solution where I can initialise a rope, with a non specific amount of points and then when updating their positions, new points may be added or some removed. My attempts to do this inside the updateAnimation() function have so far been unsuccesful.

Link to comment
Share on other sites

Once it's setup, it's created fixed lists or arrays for rendering.  You could try and set more points than you initially need and make sure you set all the unused last entries to be duplicates of your real last entry, might cause some drawing artifacts but worth a try.

 

Without creating a new Rope instance you could call the constructer on itself to re-initialise the arrays eg.

    var myRope = new PIXI.Rope(texture,points1)

then to update with new points

    PIXI.Rope.call(myRope,texture,points2)

 

Or, add a new function to do just what you want, something like this (declare before creating initial rope):

PIXI.Rope.prototype.changePoints = function (points) {
    this.points = points;

    this.vertices = new PIXI.Float32Array(points.length * 4);
    this.uvs = new PIXI.Float32Array(points.length * 4);
    this.colors = new PIXI.Float32Array(points.length * 2);
    this.indices = new PIXI.Uint16Array(points.length * 2);


    this.refresh();
};

thus using it would be:

    myRope.changePoints(points2);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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