/* * MoveIn * * Copyright (c) 2014 Renato de Pontes Pereira. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @module Creatine * @submodule Transitions **/ // namespace: this.creatine = this.creatine || {}; this.creatine.transitions = this.creatine.transitions || {}; (function() { "use strict"; /** * The MoveIn is a transition effect that slides in the new scene to * the screen. MoveIn accepts the following direction constants: LEFT, * RIGHT, TOP, BOTTOM, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT. * *

Example

* * director.replace( * new MyScene(), * new creatine.transitions.MoveIn( * creatine.LEFT, * createjs.Ease.bounceOut, * 400 * ) * ) * * @class MoveIn * @constructor * @param {Constant} direction The direction from where the new scene will * appear. * @param {Function} ease An easing function from createjs.Ease (provided by * TweenJS). * @param {Number} time The transition time in milliseconds. Default to 400. **/ var MoveIn = function(direction, ease, time) { this.initialize(direction, ease, time); } var p = MoveIn.prototype; /** * The direction from where the new scene will appear. * * @property direction * @type {Constant} **/ p.direction = null; /** * An Easing function from createjs.Ease. * * @property ease * @type {Function} **/ p.ease = null; /** * The transition time, in milliseconds * * @property time * @type {Number} **/ p.time = null; /** * Initialization method. * * @method initialize * @param {Constant} direction The direction from where the new scene will appear. * @param {Function} ease An easing function from createjs.Ease (provided * by TweenJS). * @param {Number} time The transition time in milliseconds. Default to * 400. * @protected **/ p.initialize = function(direction, ease, time) { this.direction = direction || creatine.LEFT; this.ease = ease || createjs.Ease.linear; this.time = time || 400; } /** * Performe the transition. This method is called only by Director. * * @method run * @param {Director} director The Director instance. * @param {Scene} out_scene The active scene. * @param {Scene} in_scene The new scene. * @param {Function} callback The callback function called when the * transition is done. **/ p.run = function(director, out_scene, in_scene, callback) { var canvas_w = director.stage.canvas.width; var canvas_h = director.stage.canvas.height; var properties = {}; switch (this.direction) { case creatine.LEFT: in_scene.x = -canvas_w; properties.x = 0; break; case creatine.RIGHT: in_scene.x = canvas_w; properties.x = 0; break; case creatine.TOP: in_scene.y = -canvas_h; properties.y = 0; break; case creatine.BOTTOM: in_scene.y = canvas_h; properties.y = 0; break; case creatine.TOP_LEFT: in_scene.x = -canvas_w; in_scene.y = -canvas_h; properties.x = 0; properties.y = 0; break; case creatine.TOP_RIGHT: in_scene.x = canvas_w; in_scene.y = -canvas_h; properties.x = 0; properties.y = 0; break; case creatine.BOTTOM_LEFT: in_scene.x = -canvas_w; in_scene.y = canvas_h; properties.x = 0; properties.y = 0; break; case creatine.BOTTOM_RIGHT: in_scene.x = canvas_w; in_scene.y = canvas_h; properties.x = 0; properties.y = 0; break } var tween = createjs.Tween.get(in_scene); tween.to(properties, this.time, this.ease); if (callback) { tween.call(callback); } } creatine.transitions.MoveIn = MoveIn; }());