Sign in to follow this  
DavidJAldred

Dynamic Points for Ropes

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.

Share this post


Link to post
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);

 

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.