Merge branch 'master' into rendering-cleanup

This commit is contained in:
Felipe Alfonso 2018-01-16 16:33:13 -03:00
commit a41681c21a
64 changed files with 2155 additions and 2305 deletions

View file

@ -10,12 +10,12 @@ var EventEmitter = require('eventemitter3');
var VisibilityHandler = require('./VisibilityHandler');
var AnimationManager = require('../animations/AnimationManager');
var CacheManager = require('../cache/CacheManager');
var CreateRenderer = require('./CreateRenderer');
var Data = require('../data/Data');
var GlobalCache = require('../cache/GlobalCache');
var InputManager = require('../input/InputManager');
var GlobalSceneManager = require('../scene/global/GlobalSceneManager');
var PluginManager = require('../plugins/PluginManager');
var SceneManager = require('../scene/SceneManager');
var SoundManagerCreator = require('../sound/SoundManagerCreator');
var TextureManager = require('../textures/TextureManager');
var TimeStep = require('./TimeStep');
@ -102,9 +102,9 @@ var Game = new Class({
/**
* [description]
*
* @property {Phaser.Cache.GlobalCache} cache
* @property {Phaser.Cache.CacheManager} cache
*/
this.cache = new GlobalCache(this);
this.cache = new CacheManager(this);
/**
* [description]
@ -123,9 +123,9 @@ var Game = new Class({
/**
* [description]
*
* @property {Phaser.Scenes.GlobalSceneManager} scene
* @property {Phaser.Scenes.SceneManager} scene
*/
this.scene = new GlobalSceneManager(this, this.config.sceneConfig);
this.scene = new SceneManager(this, this.config.sceneConfig);
/**
* [description]

View file

@ -1,21 +1,21 @@
var BaseCache = require('./BaseCache');
var Class = require('../utils/Class');
var GlobalCache = new Class({
var CacheManager = new Class({
initialize:
/**
* [description]
*
* @class GlobalCache
* @class CacheManager
* @memberOf Phaser.Cache
* @constructor
* @since 3.0.0
*
* @param {Phaser.Game} game - [description]
*/
function GlobalCache (game)
function CacheManager (game)
{
/**
* [description]
@ -127,7 +127,7 @@ var GlobalCache = new Class({
/**
* [description]
*
* @method Phaser.Cache.GlobalCache#addCustom
* @method Phaser.Cache.CacheManager#addCustom
* @since 3.0.0
*
* @param {string} key - [description]
@ -146,4 +146,4 @@ var GlobalCache = new Class({
});
module.exports = GlobalCache;
module.exports = CacheManager;

View file

@ -90,7 +90,7 @@ var KeyCombo = new Class({
return;
}
var matched = ProcessKeyCombo(event.data, _this);
var matched = ProcessKeyCombo(event, _this);
if (matched)
{

1062
src/scene/SceneManager.js Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,89 +0,0 @@
var Class = require('../../utils/Class');
var GlobalSceneManager = new Class({
initialize:
function GlobalSceneManager (game, sceneConfig)
{
this.game = game;
// Everything kept in here
this.keys = {};
this.scenes = [];
// Only active scenes are kept in here. They are moved here when started, and moved out when not.
// All scenes are stored in the scenes array, regardless of being active or not.
this.active = [];
// A scene pending to be added to the Scene Manager is stored in here until the manager has time to add it.
this._pending = [];
// An array of scenes waiting to be started once the game has booted
this._start = [];
if (sceneConfig)
{
if (Array.isArray(sceneConfig))
{
for (var i = 0; i < sceneConfig.length; i++)
{
// The i === 0 part just starts the first Scene given
this._pending.push({
index: i,
key: 'default',
scene: sceneConfig[i],
autoStart: (i === 0),
data: {}
});
}
}
else
{
this._pending.push({
index: 0,
key: 'default',
scene: sceneConfig,
autoStart: true,
data: {}
});
}
}
},
add: require('./inc/Add'),
boot: require('./inc/Boot'),
bootScene: require('./inc/BootScene'),
bringToTop: require('./inc/BringToTop'),
create: require('./inc/Create'),
createSceneDisplay: require('./inc/CreateSceneDisplay'),
createSceneFromFunction: require('./inc/CreateSceneFromFunction'),
createSceneFromInstance: require('./inc/CreateSceneFromInstance'),
createSceneFromObject: require('./inc/CreateSceneFromObject'),
getActiveScene: require('./inc/GetActiveScene'),
getActiveSceneIndex: require('./inc/GetActiveSceneIndex'),
getActiveSceneIndexByKey: require('./inc/GetActiveSceneIndexByKey'),
getKey: require('./inc/GetKey'),
getScene: require('./inc/GetScene'),
getSceneAt: require('./inc/GetSceneAt'),
getSceneIndex: require('./inc/GetSceneIndex'),
getSceneIndexByKey: require('./inc/GetSceneIndexByKey'),
isActive: require('./inc/IsActive'),
isSleeping: require('./inc/IsSleeping'),
loadComplete: require('./inc/LoadComplete'),
moveDown: require('./inc/MoveDown'),
moveUp: require('./inc/MoveUp'),
pause: require('./inc/Pause'),
payloadComplete: require('./inc/PayloadComplete'),
resume: require('./inc/Resume'),
sendToBack: require('./inc/SendToBack'),
sleep: require('./inc/Sleep'),
start: require('./inc/Start'),
stop: require('./inc/Stop'),
swap: require('./inc/Swap'),
swapPosition: require('./inc/SwapPosition'),
wake: require('./inc/Wake')
});
module.exports = GlobalSceneManager;

View file

@ -1,85 +0,0 @@
var Scene = require('../../local/Scene');
/**
* Adds a new Scene into the SceneManager.
* You must give each Scene a unique key by which you'll identify it.
*
* The `sceneConfig` can be:
*
* * A `Phaser.Scene` object, or an object that extends it.
* * A plain JavaScript object
* * A JavaScript ES6 Class that extends `Phaser.Scene`
* * A JavaScript ES5 prototype based Class
* * A JavaScript function
*
* If a function is given then a new Scene will be created by calling it.
*
* @method Phaser.Scenes.GlobalSceneManager#add
* @since 3.0.0
*
* @param {string} key - A unique key used to reference the Scene, i.e. `MainMenu` or `Level1`.
* @param {Phaser.Scene|object|function} sceneConfig - [description]
* @param {boolean} [autoStart=false] - If `true` the Scene will be started immediately after being added.
*
* @return {Phaser.Scene} [description]
*/
var Add = function (key, sceneConfig, autoStart)
{
if (autoStart === undefined) { autoStart = false; }
// if not booted, then put scene into a holding pattern
if (!this.game.isBooted)
{
this._pending.push({
index: this._pending.length,
key: key,
scene: sceneConfig,
autoStart: autoStart
});
return;
}
// var ok = key;
key = this.getKey(key, sceneConfig);
var newScene;
if (sceneConfig instanceof Scene)
{
newScene = this.createSceneFromInstance(key, sceneConfig);
}
else if (typeof sceneConfig === 'object')
{
sceneConfig.key = key;
newScene = this.createSceneFromObject(key, sceneConfig);
}
else if (typeof sceneConfig === 'function')
{
newScene = this.createSceneFromFunction(key, sceneConfig);
}
// Replace key in case the scene changed it
key = newScene.sys.settings.key;
this.keys[key] = newScene;
this.scenes.push(newScene);
if (autoStart || newScene.sys.settings.active)
{
if (this.game.isBooted)
{
this.start(key);
}
else
{
this._start.push(key);
}
}
return newScene;
};
module.exports = Add;

View file

@ -1,31 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#boot
* @since 3.0.0
*/
var Boot = function ()
{
var i;
var entry;
for (i = 0; i < this._pending.length; i++)
{
entry = this._pending[i];
this.add(entry.key, entry.scene, entry.autoStart);
}
for (i = 0; i < this._start.length; i++)
{
entry = this._start[i];
this.start(entry);
}
// Clear the pending lists
this._start = [];
this._pending = [];
};
module.exports = Boot;

View file

@ -1,45 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#bootScene
* @since 3.0.0
*
* @param {Phaser.Scene} scene - [description]
*/
var BootScene = function (scene)
{
if (scene.init)
{
scene.init.call(scene, scene.sys.settings.data);
}
var loader = scene.sys.load;
loader.reset();
if (scene.preload)
{
scene.preload(this.game);
// Is the loader empty?
if (loader.list.size === 0)
{
this.create(scene);
}
else
{
// Start the loader going as we have something in the queue
loader.once('complete', this.loadComplete, this);
loader.start();
}
}
else
{
// No preload? Then there was nothing to load either
this.create(scene);
}
};
module.exports = BootScene;

View file

@ -1,30 +0,0 @@
// If the arguments are strings they are assumed to be keys, otherwise they are Scene objects
// You can only swap the positions of Active (rendering / updating) Scenes. If a Scene is not active it cannot be moved.
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#bringToTop
* @since 3.0.0
*
* @param {string|Phaser.Scene} scene - [description]
*/
var BringToTop = function (scene)
{
var index = (typeof scene === 'string') ? this.getActiveSceneIndexByKey(scene) : this.getActiveSceneIndex(scene);
if (index < this.active.length)
{
var i = 0;
var entry = this.active.splice(index, 1);
for (i = 0; i < this.active.length; i++)
{
this.active[i].index = i;
}
this.active.push({ index: i, scene: entry[0].scene });
}
};
module.exports = BringToTop;

View file

@ -1,28 +0,0 @@
var SortScenes = require('./SortScenes');
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#create
* @since 3.0.0
*
* @param {Phaser.Scene} scene - [description]
*/
var Create = function (scene)
{
// Insert at the correct index, or it just all goes wrong :)
var i = this.getSceneIndex(scene);
this.active.push({ index: i, scene: scene });
// Sort the 'active' array based on the index property
this.active.sort(SortScenes);
if (scene.create)
{
scene.create.call(scene, scene.sys.settings.data);
}
};
module.exports = Create;

View file

@ -1,43 +0,0 @@
var CanvasPool = require('../../../display/canvas/CanvasPool');
var CONST = require('../../../const');
var CanvasInterpolation = require('../../../display/canvas/CanvasInterpolation');
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#createSceneDisplay
* @since 3.0.0
*
* @param {Phaser.Scene} scene - [description]
*/
var CreateSceneDisplay = function (scene)
{
var settings = scene.sys.settings;
var width = settings.width;
var height = settings.height;
var config = this.game.config;
if (config.renderType === CONST.CANVAS)
{
if (settings.renderToTexture)
{
scene.sys.canvas = CanvasPool.create(scene, width, height);
scene.sys.context = scene.sys.canvas.getContext('2d');
}
else
{
scene.sys.canvas = this.game.canvas;
scene.sys.context = this.game.context;
}
// Pixel Art mode?
if (config.pixelArt)
{
CanvasInterpolation.setCrisp(scene.sys.canvas);
}
}
};
module.exports = CreateSceneDisplay;

View file

@ -1,82 +0,0 @@
var Scene = require('../../local/Scene');
var Systems = require('../../local/Systems');
var NOOP = require('../../../utils/NOOP');
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#createSceneFromFunction
* @since 3.0.0
*
* @param {string} key - [description]
* @param {function} scene - [description]
*
* @return {Phaser.Scene} [description]
*/
var CreateSceneFromFunction = function (key, scene)
{
var newScene = new scene();
if (newScene instanceof Scene)
{
var configKey = newScene.sys.settings.key;
if (configKey !== '')
{
key = configKey;
}
if (this.keys.hasOwnProperty(key))
{
throw new Error('Cannot add a Scene with duplicate key: ' + key);
}
return this.createSceneFromInstance(key, newScene);
}
else
{
newScene.sys = new Systems(newScene);
newScene.sys.settings.key = key;
newScene.sys.init(this.game);
this.createSceneDisplay(newScene);
// Default required functions
if (!newScene.init)
{
newScene.init = NOOP;
}
if (!newScene.preload)
{
newScene.preload = NOOP;
}
if (!newScene.create)
{
newScene.create = NOOP;
}
if (!newScene.shutdown)
{
newScene.shutdown = NOOP;
}
if (!newScene.update)
{
newScene.update = NOOP;
}
if (!newScene.render)
{
newScene.render = NOOP;
}
return newScene;
}
};
module.exports = CreateSceneFromFunction;

View file

@ -1,32 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#createSceneFromInstance
* @since 3.0.0
*
* @param {string} key - [description]
* @param {Phaser.Scene} newScene - [description]
*
* @return {Phaser.Scene} [description]
*/
var CreateSceneFromInstance = function (key, newScene)
{
var configKey = newScene.sys.settings.key;
if (configKey !== '')
{
key = configKey;
}
else
{
newScene.sys.settings.key = key;
}
newScene.sys.init(this.game);
this.createSceneDisplay(newScene);
return newScene;
};
module.exports = CreateSceneFromInstance;

View file

@ -1,72 +0,0 @@
var GetValue = require('../../../utils/object/GetValue');
var NOOP = require('../../../utils/NOOP');
var Scene = require('../../local/Scene');
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#createSceneFromObject
* @since 3.0.0
*
* @param {string} key - [description]
* @param {object} sceneConfig - [description]
*
* @return {Phaser.Scene} [description]
*/
var CreateSceneFromObject = function (key, sceneConfig)
{
var newScene = new Scene(sceneConfig);
var configKey = newScene.sys.settings.key;
if (configKey !== '')
{
key = configKey;
}
else
{
newScene.sys.settings.key = key;
}
newScene.sys.init(this.game);
this.createSceneDisplay(newScene);
// Extract callbacks or set NOOP
var defaults = [ 'init', 'preload', 'create', 'shutdown', 'update', 'render' ];
for (var i = 0; i < defaults.length; i++)
{
newScene[defaults[i]] = GetValue(sceneConfig, defaults[i], NOOP);
}
// Now let's move across any other functions or properties that may exist
/*
scene: {
preload: preload,
create: create,
extend: {
hello: 1,
test: 'atari',
addImage: addImage
}
}
*/
if (sceneConfig.hasOwnProperty('extend'))
{
for (var propertyKey in sceneConfig.extend)
{
if (defaults.indexOf(propertyKey) === -1)
{
newScene[propertyKey] = sceneConfig.extend[propertyKey];
}
}
}
return newScene;
};
module.exports = CreateSceneFromObject;

View file

@ -1,24 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#getActiveScene
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scene} [description]
*/
var GetActiveScene = function (key)
{
var scene = this.getScene(key);
for (var i = 0; i < this.active.length; i++)
{
if (this.active[i].scene === scene)
{
return this.active[i];
}
}
};
module.exports = GetActiveScene;

View file

@ -1,24 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#getActiveSceneIndex
* @since 3.0.0
*
* @param {Phaser.Scene} scene - [description]
*
* @return {integer} [description]
*/
var GetActiveSceneIndex = function (scene)
{
for (var i = 0; i < this.active.length; i++)
{
if (this.active[i].scene === scene)
{
return this.active[i].index;
}
}
return -1;
};
module.exports = GetActiveSceneIndex;

View file

@ -1,26 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#getActiveSceneIndexByKey
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {integer} [description]
*/
var GetActiveSceneIndexByKey = function (key)
{
var scene = this.keys[key];
for (var i = 0; i < this.active.length; i++)
{
if (this.active[i].scene === scene)
{
return this.active[i].index;
}
}
return -1;
};
module.exports = GetActiveSceneIndexByKey;

View file

@ -1,43 +0,0 @@
var Scene = require('../../local/Scene');
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#getKey
* @since 3.0.0
*
* @param {string} key - [description]
* @param {Phaser.Scene|object|function} sceneConfig - [description]
*
* @return {string} [description]
*/
var GetKey = function (key, sceneConfig)
{
if (!key) { key = 'default'; }
if (typeof sceneConfig === 'function')
{
return key;
}
else if (sceneConfig instanceof Scene)
{
key = sceneConfig.sys.settings.key;
}
else if (typeof sceneConfig === 'object' && sceneConfig.hasOwnProperty('key'))
{
key = sceneConfig.key;
}
// By this point it's either 'default' or extracted from the Scene
if (this.keys.hasOwnProperty(key))
{
throw new Error('Cannot add a Scene with duplicate key: ' + key);
}
else
{
return key;
}
};
module.exports = GetKey;

View file

@ -1,16 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#getScene
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {Phaser.Scene} [description]
*/
var GetScene = function (key)
{
return this.keys[key];
};
module.exports = GetScene;

View file

@ -1,21 +0,0 @@
// Gets the Active scene at the given position
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#getSceneAt
* @since 3.0.0
*
* @param {integer} index - [description]
*
* @return {Phaser.Scene} [description]
*/
var GetSceneAt = function (index)
{
if (this.active[index])
{
return this.active[index].scene;
}
};
module.exports = GetSceneAt;

View file

@ -1,16 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#getSceneIndex
* @since 3.0.0
*
* @param {Phaser.Scene} scene - [description]
*
* @return {integer} [description]
*/
var GetSceneIndex = function (scene)
{
return this.scenes.indexOf(scene);
};
module.exports = GetSceneIndex;

View file

@ -1,18 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#getSceneIndexByKey
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {integer} [description]
*/
var GetSceneIndexByKey = function (key)
{
var scene = this.keys[key];
return this.scenes.indexOf(scene);
};
module.exports = GetSceneIndexByKey;

View file

@ -1,18 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#isActive
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {boolean} [description]
*/
var IsActive = function (key)
{
var entry = this.getActiveScene(key);
return (entry && entry.scene.sys.settings.active);
};
module.exports = IsActive;

View file

@ -1,23 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#isSleeping
* @since 3.0.0
*
* @param {string} key - [description]
*
* @return {boolean} [description]
*/
var IsSleeping = function (key)
{
var entry = this.getActiveScene(key);
if (entry)
{
return (!entry.scene.sys.settings.active && !entry.scene.sys.settings.visible);
}
return false;
};
module.exports = IsSleeping;

View file

@ -1,16 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#loadComplete
* @since 3.0.0
*
* @param {object} event - [description]
*/
var LoadComplete = function (loader)
{
var scene = loader.scene;
this.create(scene);
};
module.exports = LoadComplete;

View file

@ -1,27 +0,0 @@
// If the arguments are strings they are assumed to be keys, otherwise they are Scene objects
// You can only swap the positions of Active (rendering / updating) Scenes. If a Scene is not active it cannot be moved.
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#moveDown
* @since 3.0.0
*
* @param {string|Phaser.Scene} scene - [description]
*/
var MoveDown = function (scene)
{
var index = (typeof scene === 'string') ? this.getActiveSceneIndexByKey(scene) : this.getActiveSceneIndex(scene);
if (index > 0)
{
var sceneB = this.getSceneAt(index - 1);
if (sceneB)
{
this.swapPosition(scene, sceneB);
}
}
};
module.exports = MoveDown;

View file

@ -1,27 +0,0 @@
// If the arguments are strings they are assumed to be keys, otherwise they are Scene objects
// You can only swap the positions of Active (rendering / updating) Scenes. If a Scene is not active it cannot be moved.
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#moveUp
* @since 3.0.0
*
* @param {string|Phaser.Scene} scene - [description]
*/
var MoveUp = function (scene)
{
var index = (typeof scene === 'string') ? this.getActiveSceneIndexByKey(scene) : this.getActiveSceneIndex(scene);
if (index !== -1 && index < this.active.length - 1)
{
var sceneB = this.getSceneAt(index + 1);
if (sceneB)
{
this.swapPosition(scene, sceneB);
}
}
};
module.exports = MoveUp;

View file

@ -1,19 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#pause
* @since 3.0.0
*
* @param {string} key - [description]
*/
var Pause = function (key)
{
var entry = this.getActiveScene(key);
if (entry)
{
entry.scene.sys.pause();
}
};
module.exports = Pause;

View file

@ -1,16 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#payloadComplete
* @since 3.0.0
*
* @param {object} event - [description]
*/
var PayloadComplete = function (event)
{
var scene = event.loader.scene;
this.bootScene(scene);
};
module.exports = PayloadComplete;

View file

@ -1,19 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#resume
* @since 3.0.0
*
* @param {string} key - [description]
*/
var Resume = function (key)
{
var entry = this.getActiveScene(key);
if (entry)
{
entry.scene.sys.resume();
}
};
module.exports = Resume;

View file

@ -1,29 +0,0 @@
// If the arguments are strings they are assumed to be keys, otherwise they are Scene objects
// You can only swap the positions of Active (rendering / updating) Scenes. If a Scene is not active it cannot be moved.
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#sendToBack
* @since 3.0.0
*
* @param {string|Phaser.Scene} scene - [description]
*/
var SendToBack = function (scene)
{
var index = (typeof scene === 'string') ? this.getActiveSceneIndexByKey(scene) : this.getActiveSceneIndex(scene);
if (index > 0)
{
var entry = this.active.splice(index, 1);
this.active.unshift({ index: 0, scene: entry[0].scene });
for (var i = 0; i < this.active.length; i++)
{
this.active[i].index = i;
}
}
};
module.exports = SendToBack;

View file

@ -1,19 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#sleep
* @since 3.0.0
*
* @param {string} key - [description]
*/
var Sleep = function (key)
{
var entry = this.getActiveScene(key);
if (entry)
{
entry.scene.sys.sleep();
}
};
module.exports = Sleep;

View file

@ -1,29 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#sortScenes
* @since 3.0.0
*
* @param {object} sceneA - [description]
* @param {object} sceneB - [description]
*
* @return {integer} [description]
*/
var SortScenes = function (sceneA, sceneB)
{
// Sort descending
if (sceneA.index < sceneB.index)
{
return -1;
}
else if (sceneA.index > sceneB.index)
{
return 1;
}
else
{
return 0;
}
};
module.exports = SortScenes;

View file

@ -1,68 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#start
* @since 3.0.0
*
* @param {string} key - [description]
* @param {object} data - [description]
*/
var Start = function (key, data)
{
if (data === undefined) { data = {}; }
// if not booted, then put scene into a holding pattern
if (!this.game.isBooted)
{
for (var i = 0; i < this._pending.length; i++)
{
var entry = this._pending[i];
if (entry.key === key)
{
entry.autoStart = true;
entry.data = data;
}
}
return;
}
var scene = this.getScene(key);
if (scene)
{
// Already started? Nothing more to do here ...
if (this.isActive(key))
{
return;
}
scene.sys.start(data);
var loader = scene.sys.load;
// Files payload?
if (loader && Array.isArray(scene.sys.settings.files))
{
loader.reset();
if (loader.loadArray(scene.sys.settings.files))
{
loader.once('complete', this.payloadComplete, this);
loader.start();
}
else
{
this.bootScene(scene);
}
}
else
{
this.bootScene(scene);
}
}
};
module.exports = Start;

View file

@ -1,31 +0,0 @@
var SortScenes = require('./SortScenes');
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#stop
* @since 3.0.0
*
* @param {string} key - [description]
*/
var Stop = function (key)
{
var entry = this.getActiveScene(key);
if (entry)
{
entry.scene.sys.shutdown();
// Remove from the active list
var index = this.active.indexOf(entry);
if (index !== -1)
{
this.active.splice(index, 1);
this.active.sort(SortScenes);
}
}
};
module.exports = Stop;

View file

@ -1,24 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#swap
* @since 3.0.0
*
* @param {string} from - [description]
* @param {string} to - [description]
*/
var Swap = function (from, to)
{
this.sleep(from);
if (this.isSleeping(to))
{
this.wake(to);
}
else
{
this.start(to);
}
};
module.exports = Swap;

View file

@ -1,34 +0,0 @@
var SortScenes = require('./SortScenes');
// If the arguments are strings they are assumed to be keys, otherwise they are Scene objects
// You can only swap the positions of Active (rendering / updating) Scenes. If a Scene is not active it cannot be moved.
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#swapPosition
* @since 3.0.0
*
* @param {string|Phaser.Scene} scene1 - [description]
* @param {string|Phaser.Scene} scene2 - [description]
*/
var SwapPosition = function (scene1, scene2)
{
if (scene1 === scene2)
{
return;
}
var index1 = (typeof scene1 === 'string') ? this.getActiveSceneIndexByKey(scene1) : this.getActiveSceneIndex(scene1);
var index2 = (typeof scene2 === 'string') ? this.getActiveSceneIndexByKey(scene2) : this.getActiveSceneIndex(scene2);
if (index1 !== -1 && index2 !== -1 && index1 !== index2)
{
this.active[index1].index = index2;
this.active[index2].index = index1;
this.active.sort(SortScenes);
}
};
module.exports = SwapPosition;

View file

@ -1,19 +0,0 @@
/**
* [description]
*
* @method Phaser.Scenes.GlobalSceneManager#wake
* @since 3.0.0
*
* @param {string} key - [description]
*/
var Wake = function (key)
{
var entry = this.getActiveScene(key);
if (entry)
{
entry.scene.sys.wake();
}
};
module.exports = Wake;

View file

@ -195,20 +195,275 @@ var TweenManager = new Class({
return this;
},
setGlobalTimeScale: require('./inc/SetGlobalTimeScale'),
getGlobalTimeScale: require('./inc/GetGlobalTimeScale'),
getAllTweens: require('./inc/GetAllTweens'),
getTweensOf: require('./inc/GetTweensOf'),
isTweening: require('./inc/IsTweening'),
killAll: require('./inc/KillAll'),
killTweensOf: require('./inc/KillTweensOf'),
pauseAll: require('./inc/PauseAll'),
resumeAll: require('./inc/ResumeAll'),
each: require('./inc/Each'),
shutdown: require('./inc/Shutdown'),
destroy: require('./inc/Destroy')
// Passes all Tweens to the given callback.
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#each
* @since 3.0.0
*
* @param {function} callback - [description]
* @param {object} [thisArg] - [description]
* @param {...*} [arguments] - [description]
*/
each: function (callback, thisArg)
{
var args = [ null ];
for (var i = 1; i < arguments.length; i++)
{
args.push(arguments[i]);
}
for (var texture in this.list)
{
args[0] = this.list[texture];
callback.apply(thisArg, args);
}
},
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#getAllTweens
* @since 3.0.0
*
* @return {Phaser.Tweens.Tween[]} [description]
*/
getAllTweens: function ()
{
var list = this._active;
var output = [];
for (var i = 0; i < list.length; i++)
{
output.push(list[i]);
}
return output;
},
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#getGlobalTimeScale
* @since 3.0.0
*
* @return {number} [description]
*/
getGlobalTimeScale: function ()
{
return this.timeScale;
},
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#getTweensOf
* @since 3.0.0
*
* @param {object|array} target - [description]
*
* @return {Phaser.Tweens.Tween[]} [description]
*/
getTweensOf: function (target)
{
var list = this._active;
var tween;
var output = [];
var i;
if (Array.isArray(target))
{
for (i = 0; i < list.length; i++)
{
tween = list[i];
for (var t = 0; t < target.length; i++)
{
if (tween.hasTarget(target[t]))
{
output.push(tween);
}
}
}
}
else
{
for (i = 0; i < list.length; i++)
{
tween = list[i];
if (tween.hasTarget(target))
{
output.push(tween);
}
}
}
return output;
},
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#isTweening
* @since 3.0.0
*
* @param {any} target - [description]
*
* @return {boolean} [description]
*/
isTweening: function (target)
{
var list = this._active;
var tween;
for (var i = 0; i < list.length; i++)
{
tween = list[i];
if (tween.hasTarget(target) && tween.isPlaying())
{
return true;
}
}
return false;
},
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#killAll
* @since 3.0.0
*
* @return {Phaser.Tweens.TweenManager} [description]
*/
killAll: function ()
{
var tweens = this.getAllTweens();
for (var i = 0; i < tweens.length; i++)
{
tweens[i].stop();
}
return this;
},
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#killTweensOf
* @since 3.0.0
*
* @param {object|array} target - [description]
*
* @return {Phaser.Tweens.TweenManager} [description]
*/
killTweensOf: function (target)
{
var tweens = this.getTweensOf(target);
for (var i = 0; i < tweens.length; i++)
{
tweens[i].stop();
}
return this;
},
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#pauseAll
* @since 3.0.0
*
* @return {Phaser.Tweens.TweenManager} [description]
*/
pauseAll: function ()
{
var list = this._active;
for (var i = 0; i < list.length; i++)
{
list[i].pause();
}
return this;
},
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#resumeAll
* @since 3.0.0
*
* @return {Phaser.Tweens.TweenManager} [description]
*/
resumeAll: function ()
{
var list = this._active;
for (var i = 0; i < list.length; i++)
{
list[i].resume();
}
return this;
},
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#setGlobalTimeScale
* @since 3.0.0
*
* @param {float} value - [description]
*
* @return {Phaser.Tweens.TweenManager} [description]
*/
setGlobalTimeScale: function (value)
{
this.timeScale = value;
return this;
},
// Scene that owns this manager is shutting down
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#shutdown
* @since 3.0.0
*/
shutdown: function ()
{
this.killAll();
this._add = [];
this._pending = [];
this._active = [];
this._destroy = [];
this._toProcess = 0;
},
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#destroy
* @since 3.0.0
*/
destroy: function ()
{
this.shutdown();
}
// TODO: kill: function (vars, target)
});
module.exports = TweenManager;

View file

@ -1,12 +0,0 @@
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#destroy
* @since 3.0.0
*/
var Destroy = function ()
{
this.shutdown();
};
module.exports = Destroy;

View file

@ -1,30 +0,0 @@
// Passes all Tweens to the given callback.
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#each
* @since 3.0.0
*
* @param {function} callback - [description]
* @param {object} [thisArg] - [description]
* @param {...*} [arguments] - [description]
*/
var Each = function (callback, thisArg)
{
var args = [ null ];
for (var i = 1; i < arguments.length; i++)
{
args.push(arguments[i]);
}
for (var texture in this.list)
{
args[0] = this.list[texture];
callback.apply(thisArg, args);
}
};
module.exports = Each;

View file

@ -1,22 +0,0 @@
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#getAllTweens
* @since 3.0.0
*
* @return {Phaser.Tweens.Tween[]} [description]
*/
var GetAllTweens = function ()
{
var list = this._active;
var output = [];
for (var i = 0; i < list.length; i++)
{
output.push(list[i]);
}
return output;
};
module.exports = GetAllTweens;

View file

@ -1,14 +0,0 @@
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#getGlobalTimeScale
* @since 3.0.0
*
* @return {number} [description]
*/
var GetGlobalTimeScale = function ()
{
return this.timeScale;
};
module.exports = GetGlobalTimeScale;

View file

@ -1,49 +0,0 @@
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#getTweensOf
* @since 3.0.0
*
* @param {object|array} target - [description]
*
* @return {Phaser.Tweens.Tween[]} [description]
*/
var GetTweensOf = function (target)
{
var list = this._active;
var tween;
var output = [];
var i;
if (Array.isArray(target))
{
for (i = 0; i < list.length; i++)
{
tween = list[i];
for (var t = 0; t < target.length; i++)
{
if (tween.hasTarget(target[t]))
{
output.push(tween);
}
}
}
}
else
{
for (i = 0; i < list.length; i++)
{
tween = list[i];
if (tween.hasTarget(target))
{
output.push(tween);
}
}
}
return output;
};
module.exports = GetTweensOf;

View file

@ -1,29 +0,0 @@
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#isTweening
* @since 3.0.0
*
* @param {any} target - [description]
*
* @return {boolean} [description]
*/
var IsTweening = function (target)
{
var list = this._active;
var tween;
for (var i = 0; i < list.length; i++)
{
tween = list[i];
if (tween.hasTarget(target) && tween.isPlaying())
{
return true;
}
}
return false;
};
module.exports = IsTweening;

View file

@ -1,21 +0,0 @@
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#killAll
* @since 3.0.0
*
* @return {Phaser.Tweens.TweenManager} [description]
*/
var KillAll = function ()
{
var tweens = this.getAllTweens();
for (var i = 0; i < tweens.length; i++)
{
tweens[i].stop();
}
return this;
};
module.exports = KillAll;

View file

@ -1,23 +0,0 @@
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#killTweensOf
* @since 3.0.0
*
* @param {object|array} target - [description]
*
* @return {Phaser.Tweens.TweenManager} [description]
*/
var KillTweensOf = function (target)
{
var tweens = this.getTweensOf(target);
for (var i = 0; i < tweens.length; i++)
{
tweens[i].stop();
}
return this;
};
module.exports = KillTweensOf;

View file

@ -1,21 +0,0 @@
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#pauseAll
* @since 3.0.0
*
* @return {Phaser.Tweens.TweenManager} [description]
*/
var PauseAll = function ()
{
var list = this._active;
for (var i = 0; i < list.length; i++)
{
list[i].pause();
}
return this;
};
module.exports = PauseAll;

View file

@ -1,21 +0,0 @@
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#resumeAll
* @since 3.0.0
*
* @return {Phaser.Tweens.TweenManager} [description]
*/
var ResumeAll = function ()
{
var list = this._active;
for (var i = 0; i < list.length; i++)
{
list[i].resume();
}
return this;
};
module.exports = ResumeAll;

View file

@ -1,18 +0,0 @@
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#setGlobalTimeScale
* @since 3.0.0
*
* @param {float} value - [description]
*
* @return {Phaser.Tweens.TweenManager} [description]
*/
var SetGlobalTimeScale = function (value)
{
this.timeScale = value;
return this;
};
module.exports = SetGlobalTimeScale;

View file

@ -1,21 +0,0 @@
// Scene that owns this manager is shutting down
/**
* [description]
*
* @method Phaser.Tweens.TweenManager#shutdown
* @since 3.0.0
*/
var Shutdown = function ()
{
this.killAll();
this._add = [];
this._pending = [];
this._active = [];
this._destroy = [];
this._toProcess = 0;
};
module.exports = Shutdown;

View file

@ -156,17 +156,819 @@ var Tween = new Class({
this.play();
},
calcDuration: require('./inc/CalcDuration'),
init: require('./inc/Init'),
nextState: require('./inc/NextState'),
pause: require('./inc/Pause'),
play: require('./inc/Play'),
resetTweenData: require('./inc/ResetTweenData'),
resume: require('./inc/Resume'),
seek: require('./inc/Seek'),
setCallback: require('./inc/SetCallback'),
stop: require('./inc/Stop'),
update: require('./inc/Update')
/**
* [description]
*
* @method Phaser.Tweens.Tween#calcDuration
* @since 3.0.0
*/
calcDuration: function ()
{
var max = 0;
var data = this.data;
for (var i = 0; i < this.totalData; i++)
{
var tweenData = data[i];
// Set t1 (duration + hold + yoyo)
tweenData.t1 = tweenData.duration + tweenData.hold;
if (tweenData.yoyo)
{
tweenData.t1 += tweenData.duration;
}
// Set t2 (repeatDelay + duration + hold + yoyo)
tweenData.t2 = tweenData.t1 + tweenData.repeatDelay;
// Total Duration
tweenData.totalDuration = tweenData.delay + tweenData.t1;
if (tweenData.repeat === -1)
{
tweenData.totalDuration += (tweenData.t2 * 999999999999);
}
else if (tweenData.repeat > 0)
{
tweenData.totalDuration += (tweenData.t2 * tweenData.repeat);
}
if (tweenData.totalDuration > max)
{
// Get the longest TweenData from the Tween, used to calculate the Tween TD
max = tweenData.totalDuration;
}
}
// Excludes loop values
this.duration = max;
this.loopCounter = (this.loop === -1) ? 999999999999 : this.loop;
if (this.loopCounter > 0)
{
this.totalDuration = this.duration + this.completeDelay + ((this.duration + this.loopDelay) * this.loopCounter);
}
else
{
this.totalDuration = this.duration + this.completeDelay;
}
},
/**
* [description]
*
* @method Phaser.Tweens.Tween#init
* @since 3.0.0
*
* @return {boolean} Returns `true` if this Tween should be moved from the pending list to the active list by the Tween Manager.
*/
init: function ()
{
var data = this.data;
var totalTargets = this.totalTargets;
for (var i = 0; i < this.totalData; i++)
{
var tweenData = data[i];
var target = tweenData.target;
var gen = tweenData.gen;
tweenData.delay = gen.delay(i, totalTargets, target);
tweenData.duration = gen.duration(i, totalTargets, target);
tweenData.hold = gen.hold(i, totalTargets, target);
tweenData.repeat = gen.repeat(i, totalTargets, target);
tweenData.repeatDelay = gen.repeatDelay(i, totalTargets, target);
}
this.calcDuration();
this.progress = 0;
this.totalProgress = 0;
this.elapsed = 0;
this.totalElapsed = 0;
// You can't have a paused Tween if it's part of a Timeline
if (this.paused && !this.parentIsTimeline)
{
this.state = TWEEN_CONST.PAUSED;
return false;
}
else
{
return true;
}
},
/**
* [description]
*
* @method Phaser.Tweens.Tween#nextState
* @since 3.0.0
*/
nextState: function ()
{
if (this.loopCounter > 0)
{
this.elapsed = 0;
this.progress = 0;
this.loopCounter--;
var onLoop = this.callbacks.onLoop;
if (onLoop)
{
onLoop.params[1] = this.targets;
onLoop.func.apply(onLoop.scope, onLoop.params);
}
this.resetTweenData(true);
if (this.loopDelay > 0)
{
this.countdown = this.loopDelay;
this.state = TWEEN_CONST.LOOP_DELAY;
}
else
{
this.state = TWEEN_CONST.ACTIVE;
}
}
else if (this.completeDelay > 0)
{
this.countdown = this.completeDelay;
this.state = TWEEN_CONST.COMPLETE_DELAY;
}
else
{
var onComplete = this.callbacks.onComplete;
if (onComplete)
{
onComplete.params[1] = this.targets;
onComplete.func.apply(onComplete.scope, onComplete.params);
}
this.state = TWEEN_CONST.PENDING_REMOVE;
}
},
/**
* [description]
*
* @method Phaser.Tweens.Tween#pause
* @since 3.0.0
*
* @return {Phaser.Tweens.Tween} [description]
*/
pause: function ()
{
if (this.state === TWEEN_CONST.PAUSED)
{
return;
}
this.paused = true;
this._pausedState = this.state;
this.state = TWEEN_CONST.PAUSED;
return this;
},
/**
* [description]
*
* @method Phaser.Tweens.Tween#play
* @since 3.0.0
*
* @param {boolean} resetFromTimeline - [description]
*/
play: function (resetFromTimeline)
{
if (this.state === TWEEN_CONST.ACTIVE)
{
return;
}
else if (this.state === TWEEN_CONST.PENDING_REMOVE || this.state === TWEEN_CONST.REMOVED)
{
this.init();
this.parent.makeActive(this);
resetFromTimeline = true;
}
var onStart = this.callbacks.onStart;
if (this.parentIsTimeline)
{
this.resetTweenData(resetFromTimeline);
if (this.calculatedOffset === 0)
{
if (onStart)
{
onStart.params[1] = this.targets;
onStart.func.apply(onStart.scope, onStart.params);
}
this.state = TWEEN_CONST.ACTIVE;
}
else
{
this.countdown = this.calculatedOffset;
this.state = TWEEN_CONST.OFFSET_DELAY;
}
}
else if (this.paused)
{
this.paused = false;
this.parent.makeActive(this);
}
else
{
this.resetTweenData(resetFromTimeline);
this.state = TWEEN_CONST.ACTIVE;
if (onStart)
{
onStart.params[1] = this.targets;
onStart.func.apply(onStart.scope, onStart.params);
}
}
},
/**
* [description]
*
* @method Phaser.Tweens.Tween#resetTweenData
* @since 3.0.0
*
* @param {boolean} resetFromLoop - [description]
*/
resetTweenData: function (resetFromLoop)
{
var data = this.data;
for (var i = 0; i < this.totalData; i++)
{
var tweenData = data[i];
tweenData.progress = 0;
tweenData.elapsed = 0;
tweenData.repeatCounter = (tweenData.repeat === -1) ? 999999999999 : tweenData.repeat;
if (resetFromLoop)
{
tweenData.start = tweenData.getStartValue(tweenData.target, tweenData.key, tweenData.start);
tweenData.end = tweenData.getEndValue(tweenData.target, tweenData.key, tweenData.end);
tweenData.current = tweenData.start;
tweenData.state = TWEEN_CONST.PLAYING_FORWARD;
}
else if (tweenData.delay > 0)
{
tweenData.elapsed = tweenData.delay;
tweenData.state = TWEEN_CONST.DELAY;
}
else
{
tweenData.state = TWEEN_CONST.PENDING_RENDER;
}
}
},
/**
* [description]
*
* @method Phaser.Tweens.Tween#pause
* @since 3.0.0
*
* @return {Phaser.Tweens.Tween} [description]
*/
pause: function ()
{
if (this.state === TWEEN_CONST.PAUSED)
{
this.paused = false;
this.state = this._pausedState;
}
return this;
},
/**
* [description]
*
* @method Phaser.Tweens.Tween#seek
* @since 3.0.0
*
* @param {float} toPosition - A value between 0 and 1.
*/
seek: function (toPosition)
{
var data = this.data;
for (var i = 0; i < this.totalData; i++)
{
// This won't work with loop > 0 yet
var ms = this.totalDuration * toPosition;
var tweenData = data[i];
var progress = 0;
var elapsed = 0;
if (ms <= tweenData.delay)
{
progress = 0;
elapsed = 0;
}
else if (ms >= tweenData.totalDuration)
{
progress = 1;
elapsed = tweenData.duration;
}
else if (ms > tweenData.delay && ms <= tweenData.t1)
{
// Keep it zero bound
ms = Math.max(0, ms - tweenData.delay);
// Somewhere in the first playthru range
progress = ms / tweenData.t1;
elapsed = tweenData.duration * progress;
}
else if (ms > tweenData.t1 && ms < tweenData.totalDuration)
{
// Somewhere in repeat land
ms -= tweenData.delay;
ms -= tweenData.t1;
var repeats = Math.floor(ms / tweenData.t2);
// remainder
ms = ((ms / tweenData.t2) % 1) * tweenData.t2;
if (ms > tweenData.repeatDelay)
{
progress = ms / tweenData.t1;
elapsed = tweenData.duration * progress;
}
}
tweenData.progress = progress;
tweenData.elapsed = elapsed;
var v = tweenData.ease(tweenData.progress);
tweenData.current = tweenData.start + ((tweenData.end - tweenData.start) * v);
// console.log(tweenData.key, 'Seek', tweenData.target[tweenData.key], 'to', tweenData.current, 'pro', tweenData.progress, 'marker', marker, progress);
tweenData.target[tweenData.key] = tweenData.current;
}
},
/**
* [description]
*
* @method Phaser.Tweens.Tween#setCallback
* @since 3.0.0
*
* @param {string} type - [description]
* @param {function} callback - [description]
* @param {array} params - [description]
* @param {object} scope - [description]
*
* @return {Phaser.Tweens.Tween} [description]
*/
setCallback: function (type, callback, params, scope)
{
this.callbacks[type] = { func: callback, scope: scope, params: params };
return this;
},
/**
* Stops the Tween immediately, whatever stage of progress it is at and flags it for removal by the TweenManager.
*
* @method Phaser.Tweens.Tween#stop
* @since 3.0.0
*/
stop: function (resetTo)
{
if (resetTo !== undefined)
{
this.seek(resetTo);
}
this.state = TWEEN_CONST.PENDING_REMOVE;
},
/**
* [description]
*
* @method Phaser.Tweens.Tween#update
* @since 3.0.0
*
* @param {number} timestamp - [description]
* @param {float} delta - [description]
*
* @return {boolean} Returns `true` if this Tween has finished and should be removed from the Tween Manager, otherwise returns `false`.
*/
update: function (timestamp, delta)
{
if (this.state === TWEEN_CONST.PAUSED)
{
return false;
}
if (this.useFrames)
{
delta = 1 * this.parent.timeScale;
}
delta *= this.timeScale;
this.elapsed += delta;
this.progress = Math.min(this.elapsed / this.duration, 1);
this.totalElapsed += delta;
this.totalProgress = Math.min(this.totalElapsed / this.totalDuration, 1);
switch (this.state)
{
case TWEEN_CONST.ACTIVE:
var stillRunning = false;
for (var i = 0; i < this.totalData; i++)
{
if (this.updateTweenData(this, this.data[i], delta))
{
stillRunning = true;
}
}
// Anything still running? If not, we're done
if (!stillRunning)
{
this.nextState();
}
break;
case TWEEN_CONST.LOOP_DELAY:
this.countdown -= delta;
if (this.countdown <= 0)
{
this.state = TWEEN_CONST.ACTIVE;
}
break;
case TWEEN_CONST.OFFSET_DELAY:
this.countdown -= delta;
if (this.countdown <= 0)
{
var onStart = this.callbacks.onStart;
if (onStart)
{
onStart.params[1] = this.targets;
onStart.func.apply(onStart.scope, onStart.params);
}
this.state = TWEEN_CONST.ACTIVE;
}
break;
case TWEEN_CONST.COMPLETE_DELAY:
this.countdown -= delta;
if (this.countdown <= 0)
{
var onComplete = this.callbacks.onComplete;
if (onComplete)
{
onComplete.func.apply(onComplete.scope, onComplete.params);
}
this.state = TWEEN_CONST.PENDING_REMOVE;
}
break;
}
return (this.state === TWEEN_CONST.PENDING_REMOVE);
},
setStateFromEnd: function (tween, tweenData, diff)
{
if (tweenData.yoyo)
{
// We've hit the end of a Playing Forward TweenData and we have a yoyo
// Account for any extra time we got from the previous frame
tweenData.elapsed = diff;
tweenData.progress = diff / tweenData.duration;
if (tweenData.flipX)
{
tweenData.target.toggleFlipX();
}
// Problem: The flip and callback and so on gets called for every TweenData that triggers it at the same time.
// If you're tweening several properties it can fire for all of them, at once.
if (tweenData.flipY)
{
tweenData.target.toggleFlipY();
}
var onYoyo = tween.callbacks.onYoyo;
if (onYoyo)
{
// Element 1 is reserved for the target of the yoyo (and needs setting here)
onYoyo.params[1] = tweenData.target;
onYoyo.func.apply(onYoyo.scope, onYoyo.params);
}
// console.log('SetStateFromEnd-a', tweenData.start, tweenData.end);
tweenData.start = tweenData.getStartValue(tweenData.target, tweenData.key, tweenData.start);
return TWEEN_CONST.PLAYING_BACKWARD;
}
else if (tweenData.repeatCounter > 0)
{
// We've hit the end of a Playing Forward TweenData and we have a Repeat.
// So we're going to go right back to the start to repeat it again.
tweenData.repeatCounter--;
// Account for any extra time we got from the previous frame
tweenData.elapsed = diff;
tweenData.progress = diff / tweenData.duration;
// tweenData.elapsed = 0;
// tweenData.progress = 0;
if (tweenData.flipX)
{
tweenData.target.toggleFlipX();
}
if (tweenData.flipY)
{
tweenData.target.toggleFlipY();
}
var onRepeat = tween.callbacks.onRepeat;
if (onRepeat)
{
// Element 1 is reserved for the target of the repeat (and needs setting here)
onRepeat.params[1] = tweenData.target;
onRepeat.func.apply(onRepeat.scope, onRepeat.params);
}
// console.log('SetStateFromEnd-b', tweenData.start, tweenData.end);
tweenData.start = tweenData.getStartValue(tweenData.target, tweenData.key, tweenData.start);
tweenData.end = tweenData.getEndValue(tweenData.target, tweenData.key, tweenData.start);
// Delay?
if (tweenData.repeatDelay > 0)
{
tweenData.elapsed = tweenData.repeatDelay - diff;
tweenData.current = tweenData.start;
tweenData.target[tweenData.key] = tweenData.current;
return TWEEN_CONST.REPEAT_DELAY;
}
else
{
return TWEEN_CONST.PLAYING_FORWARD;
}
}
return TWEEN_CONST.COMPLETE;
},
// Was PLAYING_BACKWARD and has hit the start
setStateFromStart: function (tween, tweenData, diff)
{
if (tweenData.repeatCounter > 0)
{
tweenData.repeatCounter--;
// Account for any extra time we got from the previous frame
tweenData.elapsed = diff;
tweenData.progress = diff / tweenData.duration;
// tweenData.elapsed = 0;
// tweenData.progress = 0;
if (tweenData.flipX)
{
tweenData.target.toggleFlipX();
}
if (tweenData.flipY)
{
tweenData.target.toggleFlipY();
}
var onRepeat = tween.callbacks.onRepeat;
if (onRepeat)
{
// Element 1 is reserved for the target of the repeat (and needs setting here)
onRepeat.params[1] = tweenData.target;
onRepeat.func.apply(onRepeat.scope, onRepeat.params);
}
// console.log('SetStateFromStart', tweenData.start, tweenData.end);
tweenData.end = tweenData.getEndValue(tweenData.target, tweenData.key, tweenData.start);
// Delay?
if (tweenData.repeatDelay > 0)
{
tweenData.elapsed = tweenData.repeatDelay - diff;
tweenData.current = tweenData.start;
tweenData.target[tweenData.key] = tweenData.current;
return TWEEN_CONST.REPEAT_DELAY;
}
else
{
return TWEEN_CONST.PLAYING_FORWARD;
}
}
return TWEEN_CONST.COMPLETE;
},
// Delta is either a value in ms, or 1 if Tween.useFrames is true
updateTweenData: function (tween, tweenData, delta)
{
switch (tweenData.state)
{
case TWEEN_CONST.PLAYING_FORWARD:
case TWEEN_CONST.PLAYING_BACKWARD:
var elapsed = tweenData.elapsed;
var duration = tweenData.duration;
var diff = 0;
elapsed += delta;
if (elapsed > duration)
{
diff = elapsed - duration;
elapsed = duration;
}
var forward = (tweenData.state === TWEEN_CONST.PLAYING_FORWARD);
var progress = elapsed / duration;
var v;
if (forward)
{
v = tweenData.ease(progress);
}
else
{
v = tweenData.ease(1 - progress);
}
tweenData.current = tweenData.start + ((tweenData.end - tweenData.start) * v);
tweenData.target[tweenData.key] = tweenData.current;
tweenData.elapsed = elapsed;
tweenData.progress = progress;
var onUpdate = tween.callbacks.onUpdate;
if (onUpdate)
{
onUpdate.params[1] = tweenData.target;
onUpdate.func.apply(onUpdate.scope, onUpdate.params);
}
if (progress === 1)
{
if (forward)
{
if (tweenData.hold > 0)
{
tweenData.elapsed = tweenData.hold - diff;
tweenData.state = TWEEN_CONST.HOLD_DELAY;
}
else
{
tweenData.state = this.setStateFromEnd(tween, tweenData, diff);
}
}
else
{
tweenData.state = this.setStateFromStart(tween, tweenData, diff);
}
}
break;
case TWEEN_CONST.DELAY:
tweenData.elapsed -= delta;
if (tweenData.elapsed <= 0)
{
tweenData.elapsed = Math.abs(tweenData.elapsed);
tweenData.state = TWEEN_CONST.PENDING_RENDER;
}
break;
case TWEEN_CONST.REPEAT_DELAY:
tweenData.elapsed -= delta;
if (tweenData.elapsed <= 0)
{
tweenData.elapsed = Math.abs(tweenData.elapsed);
tweenData.state = TWEEN_CONST.PLAYING_FORWARD;
}
break;
case TWEEN_CONST.HOLD_DELAY:
tweenData.elapsed -= delta;
if (tweenData.elapsed <= 0)
{
tweenData.state = this.setStateFromEnd(tween, tweenData, Math.abs(tweenData.elapsed));
}
break;
case TWEEN_CONST.PENDING_RENDER:
tweenData.start = tweenData.getStartValue(tweenData.target, tweenData.key, tweenData.target[tweenData.key]);
tweenData.end = tweenData.getEndValue(tweenData.target, tweenData.key, tweenData.start);
tweenData.current = tweenData.start;
tweenData.target[tweenData.key] = tweenData.start;
tweenData.state = TWEEN_CONST.PLAYING_FORWARD;
break;
}
// Return TRUE if this TweenData still playing, otherwise return FALSE
return (tweenData.state !== TWEEN_CONST.COMPLETE);
}
});

View file

@ -1,62 +0,0 @@
/**
* [description]
*
* @method Phaser.Tweens.Tween#calcDuration
* @since 3.0.0
*/
var CalcDuration = function ()
{
var max = 0;
var data = this.data;
for (var i = 0; i < this.totalData; i++)
{
var tweenData = data[i];
// Set t1 (duration + hold + yoyo)
tweenData.t1 = tweenData.duration + tweenData.hold;
if (tweenData.yoyo)
{
tweenData.t1 += tweenData.duration;
}
// Set t2 (repeatDelay + duration + hold + yoyo)
tweenData.t2 = tweenData.t1 + tweenData.repeatDelay;
// Total Duration
tweenData.totalDuration = tweenData.delay + tweenData.t1;
if (tweenData.repeat === -1)
{
tweenData.totalDuration += (tweenData.t2 * 999999999999);
}
else if (tweenData.repeat > 0)
{
tweenData.totalDuration += (tweenData.t2 * tweenData.repeat);
}
if (tweenData.totalDuration > max)
{
// Get the longest TweenData from the Tween, used to calculate the Tween TD
max = tweenData.totalDuration;
}
}
// Excludes loop values
this.duration = max;
this.loopCounter = (this.loop === -1) ? 999999999999 : this.loop;
if (this.loopCounter > 0)
{
this.totalDuration = this.duration + this.completeDelay + ((this.duration + this.loopDelay) * this.loopCounter);
}
else
{
this.totalDuration = this.duration + this.completeDelay;
}
};
module.exports = CalcDuration;

View file

@ -1,49 +0,0 @@
var TWEEN_CONST = require('../const');
/**
* [description]
*
* @method Phaser.Tweens.Tween#init
* @since 3.0.0
*
* @return {boolean} Returns `true` if this Tween should be moved from the pending list to the active list by the Tween Manager.
*/
var Init = function ()
{
var data = this.data;
var totalTargets = this.totalTargets;
for (var i = 0; i < this.totalData; i++)
{
var tweenData = data[i];
var target = tweenData.target;
var gen = tweenData.gen;
tweenData.delay = gen.delay(i, totalTargets, target);
tweenData.duration = gen.duration(i, totalTargets, target);
tweenData.hold = gen.hold(i, totalTargets, target);
tweenData.repeat = gen.repeat(i, totalTargets, target);
tweenData.repeatDelay = gen.repeatDelay(i, totalTargets, target);
}
this.calcDuration();
this.progress = 0;
this.totalProgress = 0;
this.elapsed = 0;
this.totalElapsed = 0;
// You can't have a paused Tween if it's part of a Timeline
if (this.paused && !this.parentIsTimeline)
{
this.state = TWEEN_CONST.PAUSED;
return false;
}
else
{
return true;
}
};
module.exports = Init;

View file

@ -1,58 +0,0 @@
var TWEEN_CONST = require('../const');
/**
* [description]
*
* @method Phaser.Tweens.Tween#nextState
* @since 3.0.0
*/
var NextState = function ()
{
if (this.loopCounter > 0)
{
this.elapsed = 0;
this.progress = 0;
this.loopCounter--;
var onLoop = this.callbacks.onLoop;
if (onLoop)
{
onLoop.params[1] = this.targets;
onLoop.func.apply(onLoop.scope, onLoop.params);
}
this.resetTweenData(true);
if (this.loopDelay > 0)
{
this.countdown = this.loopDelay;
this.state = TWEEN_CONST.LOOP_DELAY;
}
else
{
this.state = TWEEN_CONST.ACTIVE;
}
}
else if (this.completeDelay > 0)
{
this.countdown = this.completeDelay;
this.state = TWEEN_CONST.COMPLETE_DELAY;
}
else
{
var onComplete = this.callbacks.onComplete;
if (onComplete)
{
onComplete.params[1] = this.targets;
onComplete.func.apply(onComplete.scope, onComplete.params);
}
this.state = TWEEN_CONST.PENDING_REMOVE;
}
};
module.exports = NextState;

View file

@ -1,27 +0,0 @@
var TWEEN_CONST = require('../const');
/**
* [description]
*
* @method Phaser.Tweens.Tween#pause
* @since 3.0.0
*
* @return {Phaser.Tweens.Tween} [description]
*/
var Pause = function ()
{
if (this.state === TWEEN_CONST.PAUSED)
{
return;
}
this.paused = true;
this._pausedState = this.state;
this.state = TWEEN_CONST.PAUSED;
return this;
};
module.exports = Pause;

View file

@ -1,69 +0,0 @@
var TWEEN_CONST = require('../const');
/**
* [description]
*
* @method Phaser.Tweens.Tween#play
* @since 3.0.0
*
* @param {boolean} resetFromTimeline - [description]
*/
var Play = function (resetFromTimeline)
{
if (this.state === TWEEN_CONST.ACTIVE)
{
return;
}
else if (this.state === TWEEN_CONST.PENDING_REMOVE || this.state === TWEEN_CONST.REMOVED)
{
this.init();
this.parent.makeActive(this);
resetFromTimeline = true;
}
var onStart = this.callbacks.onStart;
if (this.parentIsTimeline)
{
this.resetTweenData(resetFromTimeline);
if (this.calculatedOffset === 0)
{
if (onStart)
{
onStart.params[1] = this.targets;
onStart.func.apply(onStart.scope, onStart.params);
}
this.state = TWEEN_CONST.ACTIVE;
}
else
{
this.countdown = this.calculatedOffset;
this.state = TWEEN_CONST.OFFSET_DELAY;
}
}
else if (this.paused)
{
this.paused = false;
this.parent.makeActive(this);
}
else
{
this.resetTweenData(resetFromTimeline);
this.state = TWEEN_CONST.ACTIVE;
if (onStart)
{
onStart.params[1] = this.targets;
onStart.func.apply(onStart.scope, onStart.params);
}
}
};
module.exports = Play;

View file

@ -1,46 +0,0 @@
var TWEEN_CONST = require('../const');
/**
* [description]
*
* @method Phaser.Tweens.Tween#resetTweenData
* @since 3.0.0
*
* @param {boolean} resetFromLoop - [description]
*/
var ResetTweenData = function (resetFromLoop)
{
var data = this.data;
for (var i = 0; i < this.totalData; i++)
{
var tweenData = data[i];
tweenData.progress = 0;
tweenData.elapsed = 0;
tweenData.repeatCounter = (tweenData.repeat === -1) ? 999999999999 : tweenData.repeat;
if (resetFromLoop)
{
tweenData.start = tweenData.getStartValue(tweenData.target, tweenData.key, tweenData.start);
tweenData.end = tweenData.getEndValue(tweenData.target, tweenData.key, tweenData.end);
tweenData.current = tweenData.start;
tweenData.state = TWEEN_CONST.PLAYING_FORWARD;
}
else if (tweenData.delay > 0)
{
tweenData.elapsed = tweenData.delay;
tweenData.state = TWEEN_CONST.DELAY;
}
else
{
tweenData.state = TWEEN_CONST.PENDING_RENDER;
}
}
};
module.exports = ResetTweenData;

View file

@ -1,23 +0,0 @@
var TWEEN_CONST = require('../const');
/**
* [description]
*
* @method Phaser.Tweens.Tween#pause
* @since 3.0.0
*
* @return {Phaser.Tweens.Tween} [description]
*/
var Pause = function ()
{
if (this.state === TWEEN_CONST.PAUSED)
{
this.paused = false;
this.state = this._pausedState;
}
return this;
};
module.exports = Pause;

View file

@ -1,72 +0,0 @@
/**
* [description]
*
* @method Phaser.Tweens.Tween#seek
* @since 3.0.0
*
* @param {float} toPosition - A value between 0 and 1.
*/
var Seek = function (toPosition)
{
var data = this.data;
for (var i = 0; i < this.totalData; i++)
{
// This won't work with loop > 0 yet
var ms = this.totalDuration * toPosition;
var tweenData = data[i];
var progress = 0;
var elapsed = 0;
if (ms <= tweenData.delay)
{
progress = 0;
elapsed = 0;
}
else if (ms >= tweenData.totalDuration)
{
progress = 1;
elapsed = tweenData.duration;
}
else if (ms > tweenData.delay && ms <= tweenData.t1)
{
// Keep it zero bound
ms = Math.max(0, ms - tweenData.delay);
// Somewhere in the first playthru range
progress = ms / tweenData.t1;
elapsed = tweenData.duration * progress;
}
else if (ms > tweenData.t1 && ms < tweenData.totalDuration)
{
// Somewhere in repeat land
ms -= tweenData.delay;
ms -= tweenData.t1;
var repeats = Math.floor(ms / tweenData.t2);
// remainder
ms = ((ms / tweenData.t2) % 1) * tweenData.t2;
if (ms > tweenData.repeatDelay)
{
progress = ms / tweenData.t1;
elapsed = tweenData.duration * progress;
}
}
tweenData.progress = progress;
tweenData.elapsed = elapsed;
var v = tweenData.ease(tweenData.progress);
tweenData.current = tweenData.start + ((tweenData.end - tweenData.start) * v);
// console.log(tweenData.key, 'Seek', tweenData.target[tweenData.key], 'to', tweenData.current, 'pro', tweenData.progress, 'marker', marker, progress);
tweenData.target[tweenData.key] = tweenData.current;
}
};
module.exports = Seek;

View file

@ -1,21 +0,0 @@
/**
* [description]
*
* @method Phaser.Tweens.Tween#setCallback
* @since 3.0.0
*
* @param {string} type - [description]
* @param {function} callback - [description]
* @param {array} params - [description]
* @param {object} scope - [description]
*
* @return {Phaser.Tweens.Tween} [description]
*/
var SetCallback = function (type, callback, params, scope)
{
this.callbacks[type] = { func: callback, scope: scope, params: params };
return this;
};
module.exports = SetCallback;

View file

@ -1,19 +0,0 @@
var TWEEN_CONST = require('../const');
/**
* Stops the Tween immediately, whatever stage of progress it is at and flags it for removal by the TweenManager.
*
* @method Phaser.Tweens.Tween#stop
* @since 3.0.0
*/
var Stop = function (resetTo)
{
if (resetTo !== undefined)
{
this.seek(resetTo);
}
this.state = TWEEN_CONST.PENDING_REMOVE;
};
module.exports = Stop;

View file

@ -1,110 +0,0 @@
var TWEEN_CONST = require('../const');
var UpdateTweenData = require('./UpdateTweenData');
/**
* [description]
*
* @method Phaser.Tweens.Tween#update
* @since 3.0.0
*
* @param {number} timestamp - [description]
* @param {float} delta - [description]
*
* @return {boolean} Returns `true` if this Tween has finished and should be removed from the Tween Manager, otherwise returns `false`.
*/
var Update = function (timestamp, delta)
{
if (this.state === TWEEN_CONST.PAUSED)
{
return false;
}
if (this.useFrames)
{
delta = 1 * this.parent.timeScale;
}
delta *= this.timeScale;
this.elapsed += delta;
this.progress = Math.min(this.elapsed / this.duration, 1);
this.totalElapsed += delta;
this.totalProgress = Math.min(this.totalElapsed / this.totalDuration, 1);
switch (this.state)
{
case TWEEN_CONST.ACTIVE:
var stillRunning = false;
for (var i = 0; i < this.totalData; i++)
{
if (UpdateTweenData(this, this.data[i], delta))
{
stillRunning = true;
}
}
// Anything still running? If not, we're done
if (!stillRunning)
{
this.nextState();
}
break;
case TWEEN_CONST.LOOP_DELAY:
this.countdown -= delta;
if (this.countdown <= 0)
{
this.state = TWEEN_CONST.ACTIVE;
}
break;
case TWEEN_CONST.OFFSET_DELAY:
this.countdown -= delta;
if (this.countdown <= 0)
{
var onStart = this.callbacks.onStart;
if (onStart)
{
onStart.params[1] = this.targets;
onStart.func.apply(onStart.scope, onStart.params);
}
this.state = TWEEN_CONST.ACTIVE;
}
break;
case TWEEN_CONST.COMPLETE_DELAY:
this.countdown -= delta;
if (this.countdown <= 0)
{
var onComplete = this.callbacks.onComplete;
if (onComplete)
{
onComplete.func.apply(onComplete.scope, onComplete.params);
}
this.state = TWEEN_CONST.PENDING_REMOVE;
}
break;
}
return (this.state === TWEEN_CONST.PENDING_REMOVE);
};
module.exports = Update;

View file

@ -1,289 +0,0 @@
var TWEEN_CONST = require('../const');
var SetStateFromEnd = function (tween, tweenData, diff)
{
if (tweenData.yoyo)
{
// We've hit the end of a Playing Forward TweenData and we have a yoyo
// Account for any extra time we got from the previous frame
tweenData.elapsed = diff;
tweenData.progress = diff / tweenData.duration;
if (tweenData.flipX)
{
tweenData.target.toggleFlipX();
}
// Problem: The flip and callback and so on gets called for every TweenData that triggers it at the same time.
// If you're tweening several properties it can fire for all of them, at once.
if (tweenData.flipY)
{
tweenData.target.toggleFlipY();
}
var onYoyo = tween.callbacks.onYoyo;
if (onYoyo)
{
// Element 1 is reserved for the target of the yoyo (and needs setting here)
onYoyo.params[1] = tweenData.target;
onYoyo.func.apply(onYoyo.scope, onYoyo.params);
}
// console.log('SetStateFromEnd-a', tweenData.start, tweenData.end);
tweenData.start = tweenData.getStartValue(tweenData.target, tweenData.key, tweenData.start);
return TWEEN_CONST.PLAYING_BACKWARD;
}
else if (tweenData.repeatCounter > 0)
{
// We've hit the end of a Playing Forward TweenData and we have a Repeat.
// So we're going to go right back to the start to repeat it again.
tweenData.repeatCounter--;
// Account for any extra time we got from the previous frame
tweenData.elapsed = diff;
tweenData.progress = diff / tweenData.duration;
// tweenData.elapsed = 0;
// tweenData.progress = 0;
if (tweenData.flipX)
{
tweenData.target.toggleFlipX();
}
if (tweenData.flipY)
{
tweenData.target.toggleFlipY();
}
var onRepeat = tween.callbacks.onRepeat;
if (onRepeat)
{
// Element 1 is reserved for the target of the repeat (and needs setting here)
onRepeat.params[1] = tweenData.target;
onRepeat.func.apply(onRepeat.scope, onRepeat.params);
}
// console.log('SetStateFromEnd-b', tweenData.start, tweenData.end);
tweenData.start = tweenData.getStartValue(tweenData.target, tweenData.key, tweenData.start);
tweenData.end = tweenData.getEndValue(tweenData.target, tweenData.key, tweenData.start);
// Delay?
if (tweenData.repeatDelay > 0)
{
tweenData.elapsed = tweenData.repeatDelay - diff;
tweenData.current = tweenData.start;
tweenData.target[tweenData.key] = tweenData.current;
return TWEEN_CONST.REPEAT_DELAY;
}
else
{
return TWEEN_CONST.PLAYING_FORWARD;
}
}
return TWEEN_CONST.COMPLETE;
};
// Was PLAYING_BACKWARD and has hit the start
var SetStateFromStart = function (tween, tweenData, diff)
{
if (tweenData.repeatCounter > 0)
{
tweenData.repeatCounter--;
// Account for any extra time we got from the previous frame
tweenData.elapsed = diff;
tweenData.progress = diff / tweenData.duration;
// tweenData.elapsed = 0;
// tweenData.progress = 0;
if (tweenData.flipX)
{
tweenData.target.toggleFlipX();
}
if (tweenData.flipY)
{
tweenData.target.toggleFlipY();
}
var onRepeat = tween.callbacks.onRepeat;
if (onRepeat)
{
// Element 1 is reserved for the target of the repeat (and needs setting here)
onRepeat.params[1] = tweenData.target;
onRepeat.func.apply(onRepeat.scope, onRepeat.params);
}
// console.log('SetStateFromStart', tweenData.start, tweenData.end);
tweenData.end = tweenData.getEndValue(tweenData.target, tweenData.key, tweenData.start);
// Delay?
if (tweenData.repeatDelay > 0)
{
tweenData.elapsed = tweenData.repeatDelay - diff;
tweenData.current = tweenData.start;
tweenData.target[tweenData.key] = tweenData.current;
return TWEEN_CONST.REPEAT_DELAY;
}
else
{
return TWEEN_CONST.PLAYING_FORWARD;
}
}
return TWEEN_CONST.COMPLETE;
};
// Delta is either a value in ms, or 1 if Tween.useFrames is true
var UpdateTweenData = function (tween, tweenData, delta)
{
switch (tweenData.state)
{
case TWEEN_CONST.PLAYING_FORWARD:
case TWEEN_CONST.PLAYING_BACKWARD:
var elapsed = tweenData.elapsed;
var duration = tweenData.duration;
var diff = 0;
elapsed += delta;
if (elapsed > duration)
{
diff = elapsed - duration;
elapsed = duration;
}
var forward = (tweenData.state === TWEEN_CONST.PLAYING_FORWARD);
var progress = elapsed / duration;
var v;
if (forward)
{
v = tweenData.ease(progress);
}
else
{
v = tweenData.ease(1 - progress);
}
tweenData.current = tweenData.start + ((tweenData.end - tweenData.start) * v);
tweenData.target[tweenData.key] = tweenData.current;
tweenData.elapsed = elapsed;
tweenData.progress = progress;
var onUpdate = tween.callbacks.onUpdate;
if (onUpdate)
{
onUpdate.params[1] = tweenData.target;
onUpdate.func.apply(onUpdate.scope, onUpdate.params);
}
if (progress === 1)
{
if (forward)
{
if (tweenData.hold > 0)
{
tweenData.elapsed = tweenData.hold - diff;
tweenData.state = TWEEN_CONST.HOLD_DELAY;
}
else
{
tweenData.state = SetStateFromEnd(tween, tweenData, diff);
}
}
else
{
tweenData.state = SetStateFromStart(tween, tweenData, diff);
}
}
break;
case TWEEN_CONST.DELAY:
tweenData.elapsed -= delta;
if (tweenData.elapsed <= 0)
{
tweenData.elapsed = Math.abs(tweenData.elapsed);
tweenData.state = TWEEN_CONST.PENDING_RENDER;
}
break;
case TWEEN_CONST.REPEAT_DELAY:
tweenData.elapsed -= delta;
if (tweenData.elapsed <= 0)
{
tweenData.elapsed = Math.abs(tweenData.elapsed);
tweenData.state = TWEEN_CONST.PLAYING_FORWARD;
}
break;
case TWEEN_CONST.HOLD_DELAY:
tweenData.elapsed -= delta;
if (tweenData.elapsed <= 0)
{
tweenData.state = SetStateFromEnd(tween, tweenData, Math.abs(tweenData.elapsed));
}
break;
case TWEEN_CONST.PENDING_RENDER:
tweenData.start = tweenData.getStartValue(tweenData.target, tweenData.key, tweenData.target[tweenData.key]);
tweenData.end = tweenData.getEndValue(tweenData.target, tweenData.key, tweenData.start);
tweenData.current = tweenData.start;
tweenData.target[tweenData.key] = tweenData.start;
tweenData.state = TWEEN_CONST.PLAYING_FORWARD;
break;
}
// Return TRUE if this TweenData still playing, otherwise return FALSE
return (tweenData.state !== TWEEN_CONST.COMPLETE);
};
module.exports = UpdateTweenData;