Jump to content

Draw a line and animate it with TweenMax


H4mm3R
 Share

Recommended Posts

Hello folks,

 

I'm a newbie and I try to figure out how this framework works.
After I watched this site, I was amazed and wanted to learn more.
http://www.shanemielke.com/archives/usopen-sessions/

I'm a little bit stuck on a case.
So what I want to do is to draw 3 line that match the border of my window. That's fine, but In a second step, I'd like that this lines move without leaving the border.

 

Here is my little code for this part

// This is how I create the line	var lineArray = [];	for (var i = 0; i < 3; i++) {		var line = new PIXI.Graphics();		line.lineStyle(1, 0xf3a33f);				if(i == 0) {			line.moveTo(getRandomInt(0, window.innerWidth), window.innerHeight);			line.lineTo(getRandomInt(0, window.innerWidth), 0);		} else if(i == 1) {			line.moveTo(0, getRandomInt(0, window.innerHeight));			line.lineTo(window.innerWidth, getRandomInt(0, window.innerHeight));		} else {			line.moveTo(getRandomInt(0, window.innerWidth), window.innerHeight);			line.lineTo(window.innerWidth, getRandomInt(0, window.innerHeight));		}		line.endFill();		line.alpha = 0;		stage.addChild(line);		lineArray.push(line);	}// And this is how I want to animate itvar timeline = new TimelineMax({ paused: true });for (var i = lineArray.length - 1; i >= 0; i--) {	lineArray[i].beginFill(0xf3a33f, 1);	timeline.add(TweenMax.to( lineArray[i], .05, {alpha: 1}), 1.25);}timeline.play();

Is there anyway to do that with the timeline ?

 

Cheers guys !

Link to comment
Share on other sites

Hello,

 

You'll need to redraw your lines while you're moving your points.

You should draw your lines in the same PIXI.Graphics to improve performances too :

 

 



var isTweening = false;

var linesArray = [];
var lines = new PIXI.Graphics();
lines.lineStyle(1, 0xf3a33f);

for(...)
{
var line;

if(i == 0) {
line = [
new PIXI.Point(getRandomInt(0, window.innerWidth), window.innerHeight),
new PIXI.Point(getRandomInt(0, window.innerWidth), 0)
]

lines.moveTo(line[0].x, line[0].y);
lines.lineTo(line[1].x, line[1].y);
}
else {
}

lines.endFill();
linesArray.push(line)
}

stage.addChild(lines);


 

And then... I would create a function to change values of the points of each line:

 

 



var tweenPoints = function()
{
isTweening = true;
for(i= 0; i < linesArray.lenght; ++i)
{
// make your change on your linesArray[i] (which contains the two points of your line)
}
};


 

and in an update function called each frame:

 



var update = function()
{
if(isTweening) // if values of points for each lines are changing
{
lines.clear();

for(i= 0; i < linesArray.lenght; ++i)
{
var newLine = linesArray[i];
lines.moveTo(newLine[0].x, newLine[0].y);
lines.lineTo(newLine[1].x, newLine[1].y);

lines.endFill();
}
}
};


 

Hope it helps!

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