/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pulpcore.scene;

import pulpcore.Stage;

/**
 * Zoom transition.
 * 
 * @author eric
 */
public class ZoomTransition extends TransitionScene {
    private boolean zoomOut = false;

    public ZoomTransition zoomIn() {
        zoomOut = false;
        return this;
    }

    public ZoomTransition zoomOut() {
        zoomOut = true;
        return this;
    }

    protected void transitionStart() {
        fromSprite.setAnchor(0.5, 0.5);
        toSprite.setAnchor(0.5, 0.5);
        fromSprite.x.set(Stage.getWidth()*.5);
        toSprite.x.set(Stage.getWidth()*.5);
        fromSprite.y.set(Stage.getHeight()*.5);
        toSprite.y.set(Stage.getHeight()*.5);
        if (!zoomOut) {
            this.getMainLayer().moveToTop(fromSprite);
            fromSprite.width.animateTo(Stage.getWidth()*4, duration, easing);
            fromSprite.height.animateTo(Stage.getHeight()*4, duration, easing);
            toSprite.width.animate(0, Stage.getWidth(), duration, easing);
            toSprite.height.animate(0, Stage.getHeight(), duration, easing);
            fromSprite.alpha.animate(255, 0, duration, easing);
        } else {
            fromSprite.width.animateTo(0, duration, easing);
            fromSprite.height.animateTo(0, duration, easing);
            toSprite.width.animate(Stage.getWidth()*4, Stage.getWidth(), duration, easing);
            toSprite.height.animate(Stage.getHeight()*4, Stage.getHeight(), duration, easing);
            toSprite.alpha.animate(0, 255, duration, easing);
        }

    }

}
