Fork me on GitHub
Not signed in (Sign In)

Welcome, Guest

Want to take part in these discussions? Sign in if you have an account, or apply for one below

    • CommentAuthorradykal
    • CommentTimeSep 13th 2010 edited
     
    Currently I´m writing my own action and I would like to use a timeperiod easing (not an energyEasing) in the update method of the action.

    For example I would like to move all a particles from the current position to another with easing:

    I would use the time property as duration for the easing, but I dont know which property I can use for the counter. I could use an own one, but maybe you have a better solution.

    override public function update(emitter:Emitter, particle:Particle, time:Number):void
    {
    var p:Particle2D = Particle2D(particle);
    p.x = Cubic.easeOut(?????, currentX, targetX, time);

    }
    • CommentAuthorRichard
    • CommentTimeSep 16th 2010
     
    The time element is just the duration of this single frame. I doubt that's what you want. More likely you want the total time passed for the effect. Your custom action may be something like this.

    package
    {
    class CustomAction extends ActionBase
    {
    public var effectDuration:Number;
    public var targetX:Number;

    public function CustomAction( target:Number, duration:Number )
    {
    targetX = target;
    effectDuration = duration;
    }

    override public function update(emitter:Emitter, particle:Particle, time:Number):void
    {
    var p:Particle2D = Particle2D(particle);
    if( !p.dictionary[this] )
    {
    p.dictionary[this] = {startX:p.x, distance:targetX - p.x, timePassed:0};
    }
    var state:Object = p.dictionary[this];
    state.timePassed += time;
    p.x = Cubic.easeOut(state.timePassed, state.startX, state.distance, effectDuration);
    }
    }
    }


    You store particle specific data in the particle's dictionary, initializing it if it'snot set. Then add the time to the particle's time passed on each update.
    • CommentAuthorradykal
    • CommentTimeSep 16th 2010
     
    You are awesome, I tried similar but didnt work for me. This works perfect. I already worked with the dictionary and saved the origin particle position in it.