Jump to content

Animate drawing a stroke along a bezier path


greg500
 Share

Recommended Posts

Hey,
I have some problems with drawing the animation using pixi-tween. I want to animate a drawing of a stroke along the bezier path. I am basis on this example -> https://github.com/Nazariglez/pixi-tween/blob/master/examples/easing.html
 but my code still doesn’t work. Any idea where am I wrong?

That's the code:

var app = new PIXI.Application(1200, 800, {antialias: true});
document.body.appendChild(app.view);

var raf;
    function animate(){
      raf = window.requestAnimationFrame(animate);
      app.render(app.stage);
      PIXI.tweenManager.update();
    }
    function stop(){
      window.cancelAnimationFrame(raf);
    }
  
var path = new PIXI.tween.TweenPath();
  path.moveTo(0.4,0.4);
  path.bezierCurveTo(0.4,360.5,292.29,652.4,652.4,652.4);
  path.bezierCurveTo(87.5,65.4,105.9,47,105.9,24.89);
  path.closed = true;
  
var t = new PIXI.Graphics();
app.stage.addChild(t);

var tween = PIXI.tweenManager.createTween(t);
tween.on('update', function(delta){
 tween.path = path;
 tween.time = 13000;
 tween.easing = PIXI.tween.Easing.outBounce();
 tween.loop = true;
 tween.lineStyle(10, 0xff0000);
 tween.drawPath(path);
 tween.start();
});
animate();

 

Link to comment
Share on other sites

Yes, I called animate() and made some modifications but the stroke isn't animate along the Bezier curve. This is a code:

var app = new PIXI.Application(1200, 800, {antialias: true});
document.body.appendChild(app.view);

var path = new PIXI.tween.TweenPath();
	path.moveTo(0.4, 0.4);
	path.bezierCurveTo(0.4, 360,292, 652, 652, 652);
	path.bezierCurveTo(87, 65, 105, 47, 105, 24);
	path.closed = true;

var t = new PIXI.Graphics();
app.stage.addChild(t);

// t.lineStyle(10, 0xff0000);
// t.drawPath(path);

var tween = PIXI.tweenManager.createTween(t);
   tween.path = path;
   tween.time = 13000;
   tween.easing = PIXI.tween.Easing.outBounce();
   tween.loop = true;
   tween.on('start', function() {
	t.lineStyle(10, 0xff0000);
	t.drawPath(path); });
   tween.start();


app.ticker.add(function(delta){
	PIXI.tweenManager.update();
});

Do you have any idea what should be correct?

Link to comment
Share on other sites

  • 4 weeks later...

You have to clear the whole graphics and refill it every frame, or add more lines to the end of it. Anyway, whatever you pass to PIXI.Graphics cant be edited later, only removed completely, if you want to know why, please look in the source code or try to replicate same thing with pure webgl.

Link to comment
Share on other sites

Thank you. I understand the idea of how to animate the stroke in pure pixi.js but I wonder if there is an easy way to do this using pixi-tween. I want to use pixi-tween because it's easier to control visual aspects of my project and put quickly some design corrections (for example the speed of drawing the stroke)

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...