Jump to content

Best way to create fading trails?


kentskyo
 Share

Recommended Posts

So in Processing doing something like this:
 

void draw() {
fill(0, 12);
rect(0, 0, width, height);
float d = dist(x, y, targetX, targetY);
if (d > 1.0) {
    x += (targetX - x) * easing;
    y += (targetY - y) * easing;
}
fill(255);
ellipse(x, y, 20, 20);
}
 
Creates a fading trail by overwriting the canvas with a partial transparency layer that will build in opacity over time. I recreate the same effect with pixi.js here: 
 
 
...but I'm wondering if this is the best way to do this? Adding new graphics objects on top of new graphics objects seems like it could get me into trouble resource-wise, but I'm not sure how to simply draw an object to canvas in pixi and have it persist and then draw it again without going through the steps of creating new objects? Or perhaps there is another approach I'm missing as I'm just starting with this. Any insight appreciated. Thanks!

-K 

 
Link to comment
Share on other sites

OK, found a better way!...reusing the same graphics object...

function mainLoop() {  var d = dist(x, y, targetX, targetY);  if (d > 1.0) {    x += (targetX - x) * easing;    y += (targetY - y) * easing;    fade.beginFill(0x000000,0.03);    fade.drawRect(0, 0, renderer.width, renderer.height);    fade.endFill();                     fade.beginFill(0x0cf727);    fade.drawEllipse(x, y, 20, 20);    fade.endFill();               }  renderer.render(stage);            requestAnimationFrame(mainLoop);}

http://codepen.io/kentskyo/pen/ragamj

Link to comment
Share on other sites

  • 1 year later...

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