Jump to content
Search Community

Tween Curved Line

mattsm test
Moderator Tag

Recommended Posts

do you mean have an object move along a curved path?

you can use the BezierPlugin (see plugin explorer)

 

or do you mean draw a curved line and have an object follow it?

there are no drawing tools built into the GreenSock Tweening Platform, but you can look here to see what some people have done:

viewtopic.php?f=1&t=4819&p=19462&hilit=bezierDemo#p19462

 

if you want to animate the creation of a curved line (as if it is being drawn) do some google searches for "AS3 Drawing API animation curves"

 

or visit http://www.kglad.com/ and click on snippets and then curves

Link to comment
Share on other sites

I figured out how to Tween a curve just using ENTER_FRAME. Am I missing something in GreenSock that does this?

 

import flash.display.Shape;
import flash.events.Event;

var newMoon:Shape = new Shape();
var controlX:int = 30;
var controlY:int = 150;
var anchorX:int = 100;
var anchorY:int = 200;

newMoon.graphics.lineStyle(1, 0);
newMoon.graphics.moveTo(100, 100);
newMoon.graphics.curveTo(controlX, controlY, anchorX, anchorY);

addChild(newMoon);

addEventListener(Event.ENTER_FRAME, onEnterFrame);

function onEnterFrame(e:Event):void
{
controlX++;
newMoon.graphics.clear();
newMoon.graphics.lineStyle(1, 0);
newMoon.graphics.moveTo(100, 100);
newMoon.graphics.curveTo(controlX, controlY, anchorX, anchorY);
}

Link to comment
Share on other sites

if you were using a TweenLite/Max you could use an onUpdate callback to render your line each time the tween gets updated. this would be similar to an ENTER_FRAME event.

 

but no, GreenSock doesn't have any drawing tools.

Link to comment
Share on other sites

I got something working by binding the curve controls to an invisible movie clip. Then the movie clip can be tweened using the easing etc.

 

import flash.display.Shape;
import flash.events.Event;
import com.greensock.*;
import com.greensock.easing.*;
import flash.display.MovieClip;

var curve:Shape = new Shape();
addChild(curve);

var ctrl:MovieClip = new MovieClip;
ctrl.x = 0;
ctrl.y = 100;

var tl:TimelineMax = new TimelineMax();
tl.append(new TweenMax(ctrl,10,{x:300,y:30,onUpdate:drawCurve,ease:Bounce.easeOut}));

function drawCurve():void
{
curve.graphics.clear();
curve.graphics.lineStyle(4, 0);
curve.graphics.moveTo(100, 100);
curve.graphics.curveTo(ctrl.x, ctrl.y, 200, 200);
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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