hyperandroid / CAAT

Canvas Advanced Animation Toolkit
hyperandroid.github.com/CAAT
MIT License
727 stars 116 forks source link

Alpha Behavior animation #100

Closed fracasula closed 12 years ago

fracasula commented 12 years ago

Hi, I've created a circle with some children inside it. I'm trying to setting alpha for all the children (but not to the parent) when the user clicks on the parent circle. Alpha has been applied but instantly, so without any animation.

My code in children class:

var selectionHandler = function (mouseEvent) {
    var actor = mouseEvent.source;

    for (var i = 0; i < actor.getNumChildren(); i++) {
        var child = actor.getChildAt(i);
        child.addBehavior(new CAAT.AlphaBehavior().setFrameTime(0, 500).setValues(0.5, 1));
        child.selected = true;
    }
};

this.actor.mouseClick = selectionHandler;

Notes:

hyperandroid commented 12 years ago

The problem is the call to setFrameTime. This functions sets time globally related to the scene's timeline. the values 0,500 mean: take 500ms from 0 time globally from the timeline. This zero time has already elapsed, and more than 500ms have elapsed since then, so no animation. This method is primarily to schedule events in the future.

you can change it to something like setFrameTime(scene.time,500) if you have a reference to the scene, or setFrameTime( CAAT.getCurrentScene().time, 500 ) or even setFrameTime( CAAT.getCurrentSceneTime(), 500 ). These methods are always handy.

this way of doing things maybe cumbersome.

instead use the method: setDelayTime(0, 500). This one, sets behavior starting time from current scene time, so you don't have to worry. the behavior will start rigth now, and take 500ms.

you can call setDelayTime(1000,500), and the behavior start will be scheduled 1 second in the future.

Hope that helps.

2012/11/27 Francesco Casula notifications@github.com

Hi, I've created a circle with some children inside it. I'm trying to setting alpha for all the children (but not to the parent) when the user clicks on the parent circle. Alpha has been applied but instantly, so without any animation.

My code in children class:

var selectionHandler = function (mouseEvent) { var actor = mouseEvent.source;

for (var i = 0; i < actor.getNumChildren(); i++) {
    var child = actor.getChildAt(i);
    child.addBehavior(new CAAT.AlphaBehavior().setFrameTime(0, 500).setValues(0.5, 1));
    child.selected = true;
}

};

this.actor.mouseClick = selectionHandler;

Notes:

  • this.actor (the parent) is an istance of the *CAAT.ShapeActor class
  • and children too
  • when the user clicks, the children have been already rendered and are moving across the canvas :)

    — Reply to this email directly or view it on GitHubhttps://github.com/hyperandroid/CAAT/issues/100.