Huge update to move all classes to common Phaser Class format. Tidying up lots. Removing un-needed files.

This commit is contained in:
photonstorm 2017-06-30 15:47:51 +01:00
parent 03f217a277
commit e119e3a3fc
45 changed files with 979 additions and 1126 deletions

1
v3/.gitignore vendored
View file

@ -13,3 +13,4 @@ node_modules/
dist/
/npm-debug.log
out/
src/checksum.js

View file

@ -1,3 +1,4 @@
var Class = require('../../utils/Class');
var GetValue = require('../../utils/object/GetValue');
var GetFrames = require('./GetFrames');
@ -8,97 +9,97 @@ var GetFrames = require('./GetFrames');
// Game Objects have the Animation Component, which are like playheads to global Animations (these objects)
// So multiple Game Objects can have playheads all pointing to this one Animation instance
var Animation = function (manager, key, config)
{
this.manager = manager;
var Animation = new Class({
this.key = key;
initialize:
// A frame based animation (as opposed to a bone based animation)
this.type = 'frame';
// Extract all the frame data into the frames array
this.frames = GetFrames(manager.textureManager, GetValue(config, 'frames', []));
// The frame rate of playback in frames per second (default 24 if duration is null)
this.frameRate = GetValue(config, 'framerate', null);
// How long the animation should play for. If frameRate is set it overrides this value
// otherwise frameRate is derived from duration
this.duration = GetValue(config, 'duration', null);
if (this.duration === null && this.frameRate === null)
function Animation (manager, key, config)
{
// No duration or frameRate given, use default frameRate of 24fps
this.frameRate = 24;
this.duration = this.frameRate / this.frames.length;
}
else if (this.duration && this.frameRate === null)
{
// Duration given but no frameRate, so set the frameRate based on duration
// I.e. 12 frames in the animation, duration = 4 (4000 ms)
// So frameRate is 12 / 4 = 3 fps
this.frameRate = this.frames.length / this.duration;
}
else
{
// frameRate given, derive duration from it (even if duration also specified)
// I.e. 15 frames in the animation, frameRate = 30 fps
// So duration is 15 / 30 = 0.5 (half a second)
this.duration = this.frames.length / this.frameRate;
}
this.manager = manager;
// ms per frame (without including frame specific modifiers)
this.msPerFrame = 1000 / this.frameRate;
this.key = key;
// Skip frames if the time lags, or always advanced anyway?
this.skipMissedFrames = GetValue(config, 'skipMissedFrames', true);
// A frame based animation (as opposed to a bone based animation)
this.type = 'frame';
// Delay before starting playback (in seconds)
this.delay = GetValue(config, 'delay', 0);
// Extract all the frame data into the frames array
this.frames = GetFrames(manager.textureManager, GetValue(config, 'frames', []));
// Number of times to repeat the animation (-1 for infinity)
this.repeat = GetValue(config, 'repeat', 0);
// The frame rate of playback in frames per second (default 24 if duration is null)
this.frameRate = GetValue(config, 'framerate', null);
// Delay before the repeat starts (in seconds)
this.repeatDelay = GetValue(config, 'repeatDelay', 0);
// How long the animation should play for. If frameRate is set it overrides this value
// otherwise frameRate is derived from duration
this.duration = GetValue(config, 'duration', null);
// Should the animation yoyo? (reverse back down to the start) before repeating?
this.yoyo = GetValue(config, 'yoyo', false);
if (this.duration === null && this.frameRate === null)
{
// No duration or frameRate given, use default frameRate of 24fps
this.frameRate = 24;
this.duration = this.frameRate / this.frames.length;
}
else if (this.duration && this.frameRate === null)
{
// Duration given but no frameRate, so set the frameRate based on duration
// I.e. 12 frames in the animation, duration = 4 (4000 ms)
// So frameRate is 12 / 4 = 3 fps
this.frameRate = this.frames.length / this.duration;
}
else
{
// frameRate given, derive duration from it (even if duration also specified)
// I.e. 15 frames in the animation, frameRate = 30 fps
// So duration is 15 / 30 = 0.5 (half a second)
this.duration = this.frames.length / this.frameRate;
}
// Should sprite.visible = true when the animation starts to play?
this.showOnStart = GetValue(config, 'showOnStart', false);
// ms per frame (without including frame specific modifiers)
this.msPerFrame = 1000 / this.frameRate;
// Should sprite.visible = false when the animation finishes?
this.hideOnComplete = GetValue(config, 'hideOnComplete', false);
// Skip frames if the time lags, or always advanced anyway?
this.skipMissedFrames = GetValue(config, 'skipMissedFrames', true);
// Callbacks
this.callbackScope = GetValue(config, 'callbackScope', this);
// Delay before starting playback (in seconds)
this.delay = GetValue(config, 'delay', 0);
this.onStart = GetValue(config, 'onStart', false);
this.onStartParams = GetValue(config, 'onStartParams', []);
// Number of times to repeat the animation (-1 for infinity)
this.repeat = GetValue(config, 'repeat', 0);
this.onRepeat = GetValue(config, 'onRepeat', false);
this.onRepeatParams = GetValue(config, 'onRepeatParams', []);
// Delay before the repeat starts (in seconds)
this.repeatDelay = GetValue(config, 'repeatDelay', 0);
// Called for EVERY frame of the animation.
// See AnimationFrame.onUpdate for a frame specific callback.
this.onUpdate = GetValue(config, 'onUpdate', false);
this.onUpdateParams = GetValue(config, 'onUpdateParams', []);
// Should the animation yoyo? (reverse back down to the start) before repeating?
this.yoyo = GetValue(config, 'yoyo', false);
this.onComplete = GetValue(config, 'onComplete', false);
this.onCompleteParams = GetValue(config, 'onCompleteParams', []);
// Should sprite.visible = true when the animation starts to play?
this.showOnStart = GetValue(config, 'showOnStart', false);
// Global pause, effects all Game Objects using this Animation instance
this.paused = false;
// Should sprite.visible = false when the animation finishes?
this.hideOnComplete = GetValue(config, 'hideOnComplete', false);
this.manager.events.on('PAUSE_ALL_ANIMATION_EVENT', this.pause.bind(this));
this.manager.events.on('RESUME_ALL_ANIMATION_EVENT', this.resume.bind(this));
};
// Callbacks
this.callbackScope = GetValue(config, 'callbackScope', this);
Animation.prototype.constructor = Animation;
this.onStart = GetValue(config, 'onStart', false);
this.onStartParams = GetValue(config, 'onStartParams', []);
Animation.prototype = {
this.onRepeat = GetValue(config, 'onRepeat', false);
this.onRepeatParams = GetValue(config, 'onRepeatParams', []);
// Called for EVERY frame of the animation.
// See AnimationFrame.onUpdate for a frame specific callback.
this.onUpdate = GetValue(config, 'onUpdate', false);
this.onUpdateParams = GetValue(config, 'onUpdateParams', []);
this.onComplete = GetValue(config, 'onComplete', false);
this.onCompleteParams = GetValue(config, 'onCompleteParams', []);
// Global pause, effects all Game Objects using this Animation instance
this.paused = false;
this.manager.events.on('PAUSE_ALL_ANIMATION_EVENT', this.pause.bind(this));
this.manager.events.on('RESUME_ALL_ANIMATION_EVENT', this.resume.bind(this));
},
addFrame: require('./AddFrame'),
addFrameAt: require('./AddFrameAt'),
@ -131,6 +132,7 @@ Animation.prototype = {
{
}
};
});
module.exports = Animation;

View file

@ -4,10 +4,10 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Map = require('../../structs/Map');
var Class = require('../../utils/Class');
var Components = require('./components/');
var EventDispatcher = require('../../events/EventDispatcher');
var Event = require('./events');
var Map = require('../../structs/Map');
/**
* Animations are managed by the global AnimationManager. This is a singleton class that is
@ -20,24 +20,24 @@ var Event = require('./events');
* @class Phaser.AnimationManager
* @constructor
*/
var AnimationManager = function (game)
{
this.game = game;
var AnimationManager = new Class({
this.textureManager = null;
initialize:
this.events = new EventDispatcher();
function AnimationManager (game)
{
this.game = game;
this.globalTimeScale = 1;
this.textureManager = null;
this.anims = new Map();
this.events = new EventDispatcher();
this.paused = false;
};
this.globalTimeScale = 1;
AnimationManager.prototype.constructor = AnimationManager;
this.anims = new Map();
AnimationManager.prototype = {
this.paused = false;
},
boot: function (textureManager)
{
@ -62,6 +62,7 @@ AnimationManager.prototype = {
{
// TODO
}
};
});
module.exports = AnimationManager;

View file

@ -4,92 +4,97 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var MATH = require('../math');
var Class = require('../utils/Class');
var CONST = require('../const');
var NOOP = require('../utils/NOOP');
var GetValue = require('../utils/object/GetValue');
var MATH = require('../math');
var NOOP = require('../utils/NOOP');
var ValueToColor = require('../graphics/color/ValueToColor');
var defaultBannerColor = [
'#ff0000',
'#ffff00',
'#00ff00',
'#00ffff',
'#000000'
];
var Config = new Class({
var defaultBannerTextColor = '#ffffff';
initialize:
var Config = function (config)
{
if (config === undefined) { config = {}; }
function Config (config)
{
if (config === undefined) { config = {}; }
this.width = GetValue(config, 'width', 1024);
this.height = GetValue(config, 'height', 768);
this.zoom = GetValue(config, 'zoom', 1);
var defaultBannerColor = [
'#ff0000',
'#ffff00',
'#00ff00',
'#00ffff',
'#000000'
];
this.resolution = GetValue(config, 'resolution', 1);
var defaultBannerTextColor = '#ffffff';
this.renderType = GetValue(config, 'type', CONST.AUTO);
this.width = GetValue(config, 'width', 1024);
this.height = GetValue(config, 'height', 768);
this.zoom = GetValue(config, 'zoom', 1);
this.parent = GetValue(config, 'parent', null);
this.canvas = GetValue(config, 'canvas', null);
this.canvasStyle = GetValue(config, 'canvasStyle', null);
this.resolution = GetValue(config, 'resolution', 1);
this.stateConfig = GetValue(config, 'state', null);
this.renderType = GetValue(config, 'type', CONST.AUTO);
this.seed = GetValue(config, 'seed', [ (Date.now() * Math.random()).toString() ]);
this.parent = GetValue(config, 'parent', null);
this.canvas = GetValue(config, 'canvas', null);
this.canvasStyle = GetValue(config, 'canvasStyle', null);
MATH.RND.init(this.seed);
this.stateConfig = GetValue(config, 'state', null);
this.gameTitle = GetValue(config, 'title', '');
this.gameURL = GetValue(config, 'url', 'http://phaser.io');
this.gameVersion = GetValue(config, 'version', '');
this.seed = GetValue(config, 'seed', [ (Date.now() * Math.random()).toString() ]);
// Input
this.inputKeyboard = GetValue(config, 'input.keyboard', true);
this.inputKeyboardEventTarget = GetValue(config, 'input.keyboard.target', window);
MATH.RND.init(this.seed);
this.inputMouse = GetValue(config, 'input.mouse', true);
this.inputMouseEventTarget = GetValue(config, 'input.mouse.target', null);
this.gameTitle = GetValue(config, 'title', '');
this.gameURL = GetValue(config, 'url', 'http://phaser.io');
this.gameVersion = GetValue(config, 'version', '');
// If you do: { banner: false } it won't display any banner at all
this.hideBanner = (GetValue(config, 'banner', null) === false);
// Input
this.inputKeyboard = GetValue(config, 'input.keyboard', true);
this.inputKeyboardEventTarget = GetValue(config, 'input.keyboard.target', window);
this.hidePhaser = GetValue(config, 'banner.hidePhaser', false);
this.bannerTextColor = GetValue(config, 'banner.text', defaultBannerTextColor);
this.bannerBackgroundColor = GetValue(config, 'banner.background', defaultBannerColor);
this.inputMouse = GetValue(config, 'input.mouse', true);
this.inputMouseEventTarget = GetValue(config, 'input.mouse.target', null);
// Frame Rate config
// fps: {
// min: 10,
// target: 60,
// max: 120
// forceSetTimeOut: false,
// deltaHistory: 10
// }
// If you do: { banner: false } it won't display any banner at all
this.hideBanner = (GetValue(config, 'banner', null) === false);
this.fps = GetValue(config, 'fps', null);
this.hidePhaser = GetValue(config, 'banner.hidePhaser', false);
this.bannerTextColor = GetValue(config, 'banner.text', defaultBannerTextColor);
this.bannerBackgroundColor = GetValue(config, 'banner.background', defaultBannerColor);
this.pixelArt = GetValue(config, 'pixelArt', false);
this.transparent = GetValue(config, 'transparent', false);
this.clearBeforeRender = GetValue(config, 'clearBeforeRender', true);
this.backgroundColor = ValueToColor(GetValue(config, 'backgroundColor', 0));
this.preserveDrawingBuffer = ValueToColor(GetValue(config, 'preserveDrawingBuffer', false));
// Frame Rate config
// fps: {
// min: 10,
// target: 60,
// max: 120
// forceSetTimeOut: false,
// deltaHistory: 10
// }
// Callbacks
this.preBoot = GetValue(config, 'callbacks.preBoot', NOOP);
this.postBoot = GetValue(config, 'callbacks.postBoot', NOOP);
this.fps = GetValue(config, 'fps', null);
this.useTicker = GetValue(config, 'useTicker', false);
this.pixelArt = GetValue(config, 'pixelArt', false);
this.transparent = GetValue(config, 'transparent', false);
this.clearBeforeRender = GetValue(config, 'clearBeforeRender', true);
this.backgroundColor = ValueToColor(GetValue(config, 'backgroundColor', 0));
this.preserveDrawingBuffer = ValueToColor(GetValue(config, 'preserveDrawingBuffer', false));
// Default / Missing Images
var pngPrefix = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAg';
// Callbacks
this.preBoot = GetValue(config, 'callbacks.preBoot', NOOP);
this.postBoot = GetValue(config, 'callbacks.postBoot', NOOP);
this.defaultImage = GetValue(config, 'images.default', pngPrefix + 'AQMAAABJtOi3AAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABVJREFUeF7NwIEAAAAAgKD9qdeocAMAoAABm3DkcAAAAABJRU5ErkJggg==');
this.missingImage = GetValue(config, 'images.missing', pngPrefix + 'CAIAAAD8GO2jAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJ9JREFUeNq01ssOwyAMRFG46v//Mt1ESmgh+DFmE2GPOBARKb2NVjo+17PXLD8a1+pl5+A+wSgFygymWYHBb0FtsKhJDdZlncG2IzJ4ayoMDv20wTmSMzClEgbWYNTAkQ0Z+OJ+A/eWnAaR9+oxCF4Os0H8htsMUp+pwcgBBiMNnAwF8GqIgL2hAzaGFFgZauDPKABmowZ4GL369/0rwACp2yA/ttmvsQAAAABJRU5ErkJggg==');
};
this.useTicker = GetValue(config, 'useTicker', false);
Config.prototype.constructor = Config;
// Default / Missing Images
var pngPrefix = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAg';
this.defaultImage = GetValue(config, 'images.default', pngPrefix + 'AQMAAABJtOi3AAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABVJREFUeF7NwIEAAAAAgKD9qdeocAMAoAABm3DkcAAAAABJRU5ErkJggg==');
this.missingImage = GetValue(config, 'images.missing', pngPrefix + 'CAIAAAD8GO2jAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAJ9JREFUeNq01ssOwyAMRFG46v//Mt1ESmgh+DFmE2GPOBARKb2NVjo+17PXLD8a1+pl5+A+wSgFygymWYHBb0FtsKhJDdZlncG2IzJ4ayoMDv20wTmSMzClEgbWYNTAkQ0Z+OJ+A/eWnAaR9+oxCF4Os0H8htsMUp+pwcgBBiMNnAwF8GqIgL2hAzaGFFgZauDPKABmowZ4GL369/0rwACp2yA/ttmvsQAAAABJRU5ErkJggg==');
}
});
module.exports = Config;

View file

@ -23,14 +23,14 @@ var DebugHeader = function (game)
if (!ie)
{
var c = '';
var args = [c];
var args = [ c ];
if (Array.isArray(config.bannerBackgroundColor))
{
var lastColor;
config.bannerBackgroundColor.forEach(function(color) {
config.bannerBackgroundColor.forEach(function (color)
{
c = c.concat('%c ');
args.push('background: ' + color);
@ -86,7 +86,6 @@ var DebugHeader = function (game)
// Keep this during dev build only
console.log(CHECKSUM.build);
};
module.exports = DebugHeader;

View file

@ -1,4 +1,5 @@
var Class = require('../utils/Class');
var Config = require('./Config');
var DebugHeader = require('./DebugHeader');
var Device = require('../device');
@ -9,79 +10,81 @@ var EventDispatcher = require('../events/EventDispatcher');
var VisibilityHandler = require('./VisibilityHandler');
var AnimationManager = require('../animation/manager/AnimationManager');
var Cache = require('../cache/Cache');
var CreateRenderer = require('./CreateRenderer');
var Data = require('../components/Data');
var GlobalCache = require('../cache/GlobalCache');
var GlobalInputManager = require('../input/GlobalInputManager');
var GlobalStateManager = require('../state/GlobalStateManager');
var TextureManager = require('../textures/TextureManager');
var TimeStep = require('./TimeStep');
var Game = function (config)
{
this.config = new Config(config);
var Game = new Class({
this.renderer = null;
this.canvas = null;
this.context = null;
initialize:
this.isBooted = false;
this.isRunning = false;
function Game (config)
{
this.config = new Config(config);
/**
* @property {EventDispatcher} events - Global / Global Game System Events
*/
this.events = new EventDispatcher();
this.renderer = null;
this.canvas = null;
this.context = null;
/**
* @property {Phaser.AnimationManager} anims - Reference to the Phaser Animation Manager.
*/
this.anims = new AnimationManager(this);
this.isBooted = false;
this.isRunning = false;
/**
* @property {Phaser.TextureManager} textures - Reference to the Phaser Texture Manager.
*/
this.textures = new TextureManager(this);
/**
* @property {EventDispatcher} events - Global / Global Game System Events
*/
this.events = new EventDispatcher();
/**
* @property {Phaser.Cache} cache - Reference to the assets cache.
*/
this.cache = new Cache();
/**
* @property {Phaser.AnimationManager} anims - Reference to the Phaser Animation Manager.
*/
this.anims = new AnimationManager(this);
/**
* @property {Phaser.Data} registry - Game wide data store.
*/
this.registry = new Data(this);
/**
* @property {Phaser.TextureManager} textures - Reference to the Phaser Texture Manager.
*/
this.textures = new TextureManager(this);
/**
* @property {Phaser.Input} input - Reference to the input manager
*/
this.input = new GlobalInputManager(this, this.config);
/**
* @property {Phaser.Cache} cache - Reference to the assets cache.
*/
this.cache = new GlobalCache(this);
/**
* @property {Phaser.GlobalStateManager} state - The StateManager. Phaser instance specific.
*/
this.state = new GlobalStateManager(this, this.config.stateConfig);
/**
* @property {Phaser.Data} registry - Game wide data store.
*/
this.registry = new Data(this);
/**
* @property {Phaser.Device} device - Contains device information and capabilities (singleton)
*/
this.device = Device;
/**
* @property {Phaser.Input} input - Reference to the input manager
*/
this.input = new GlobalInputManager(this, this.config);
/**
* @property {Phaser.MainLoop} mainloop - Main Loop handler.
* @protected
*/
this.loop = new TimeStep(this, this.config.fps);
/**
* @property {Phaser.GlobalStateManager} state - The StateManager. Phaser instance specific.
*/
this.state = new GlobalStateManager(this, this.config.stateConfig);
// Wait for the DOM Ready event, then call boot.
DOMContentLoaded(this.boot.bind(this));
/**
* @property {Phaser.Device} device - Contains device information and capabilities (singleton)
*/
this.device = Device;
// For debugging only
window.game = this;
};
/**
* @property {Phaser.MainLoop} mainloop - Main Loop handler.
* @protected
*/
this.loop = new TimeStep(this, this.config.fps);
Game.prototype = {
// Wait for the DOM Ready event, then call boot.
DOMContentLoaded(this.boot.bind(this));
// For debugging only
window.game = this;
},
boot: function ()
{
@ -179,8 +182,7 @@ Game.prototype = {
{
this.loop.focus();
}
};
Game.prototype.constructor = Game;
});
module.exports = Game;

View file

@ -1,3 +1,11 @@
// Currently un-used
// Currently un-used
// Currently un-used
// Currently un-used
// Currently un-used
// Currently un-used
// Currently un-used
var NOOP = require('../utils/NOOP');
var RequestAnimationFrame = require('../dom/RequestAnimationFrame');

View file

@ -1,5 +1,6 @@
var NOOP = require('../utils/NOOP');
var Class = require('../utils/Class');
var GetValue = require('../utils/object/GetValue');
var NOOP = require('../utils/NOOP');
var RequestAnimationFrame = require('../dom/RequestAnimationFrame');
// Frame Rate config
@ -13,66 +14,65 @@ var RequestAnimationFrame = require('../dom/RequestAnimationFrame');
// }
// http://www.testufo.com/#test=animation-time-graph
//
var TimeStep = function (game, config)
{
this.game = game;
var TimeStep = new Class({
this.raf = new RequestAnimationFrame();
initialize:
this.started = false;
this.running = false;
function TimeStep (game, config)
{
this.game = game;
this.minFps = GetValue(config, 'min', 5);
this.maxFps = GetValue(config, 'max', 120);
this.targetFps = GetValue(config, 'target', 60);
this.raf = new RequestAnimationFrame();
this._min = 1000 / this.minFps; // 200ms between frames (i.e. super slow!)
this._max = 1000 / this.maxFps; // 8.333ms between frames (i.e. super fast, 120Hz displays)
this._target = 1000 / this.targetFps; // 16.666ms between frames (i.e. normal)
this.started = false;
this.running = false;
// 200 / 1000 = 0.2 (5fps)
// 8.333 / 1000 = 0.008333 (120fps)
// 16.666 / 1000 = 0.01666 (60fps)
this.minFps = GetValue(config, 'min', 5);
this.maxFps = GetValue(config, 'max', 120);
this.targetFps = GetValue(config, 'target', 60);
/**
* @property {number} fps - An exponential moving average of the frames per second.
* @readOnly
*/
this.actualFps = this.targetFps;
this._min = 1000 / this.minFps; // 200ms between frames (i.e. super slow!)
this._max = 1000 / this.maxFps; // 8.333ms between frames (i.e. super fast, 120Hz displays)
this._target = 1000 / this.targetFps; // 16.666ms between frames (i.e. normal)
this.nextFpsUpdate = 0;
this.framesThisSecond = 0;
// 200 / 1000 = 0.2 (5fps)
// 8.333 / 1000 = 0.008333 (120fps)
// 16.666 / 1000 = 0.01666 (60fps)
this.callback = NOOP;
/**
* @property {number} fps - An exponential moving average of the frames per second.
* @readOnly
*/
this.actualFps = this.targetFps;
this.forceSetTimeOut = GetValue(config, 'forceSetTimeOut', false);
this.nextFpsUpdate = 0;
this.framesThisSecond = 0;
this.time = 0;
this.startTime = 0;
this.lastTime = 0;
this.frame = 0;
this.callback = NOOP;
this.inFocus = true;
this.forceSetTimeOut = GetValue(config, 'forceSetTimeOut', false);
this._pauseTime = 0;
this._coolDown = 0;
this.time = 0;
this.startTime = 0;
this.lastTime = 0;
this.frame = 0;
this.delta = 0;
this.deltaIndex = 0;
this.deltaHistory = [];
this.deltaSmoothingMax = GetValue(config, 'deltaHistory', 10);
this.panicMax = GetValue(config, 'panicMax', 120);
this.inFocus = true;
// The actual elapsed time in ms between one update and the next.
// No smoothing, no capping, no averaging. So please be aware of this when using the contents of this property.
this.rawDelta = 0;
};
this._pauseTime = 0;
this._coolDown = 0;
TimeStep.prototype.constructor = TimeStep;
this.delta = 0;
this.deltaIndex = 0;
this.deltaHistory = [];
this.deltaSmoothingMax = GetValue(config, 'deltaHistory', 10);
this.panicMax = GetValue(config, 'panicMax', 120);
TimeStep.prototype = {
// The actual elapsed time in ms between one update and the next.
// No smoothing, no capping, no averaging. So please be aware of this when using the contents of this property.
this.rawDelta = 0;
},
// Called when the DOM window.onBlur event triggers
blur: function ()
@ -366,7 +366,13 @@ TimeStep.prototype = {
this.raf.stop();
return this;
},
destroy: function ()
{
}
};
});
module.exports = TimeStep;

View file

@ -1,17 +1,19 @@
var CacheEntry = require('./CacheEntry');
var Events = require('./events');
var Class = require('../utils/Class');
var EventDispatcher = require('../events/EventDispatcher');
var Events = require('./events');
var BaseCache = function ()
{
this.entries = new Map();
// Phaser.Cache.BaseCache
this.events = new EventDispatcher();
};
var BaseCache = new Class({
BaseCache.prototype.constructor = BaseCache;
initialize:
BaseCache.prototype = {
function BaseCache ()
{
this.entries = new Map();
this.events = new EventDispatcher();
},
add: function (key, data)
{
@ -47,6 +49,6 @@ BaseCache.prototype = {
this.entries.clear();
}
};
});
module.exports = BaseCache;

36
v3/src/cache/Cache.js vendored
View file

@ -1,36 +0,0 @@
var BaseCache = require('./BaseCache');
var Cache = function ()
{
this.sound = new BaseCache();
this.video = new BaseCache();
this.text = new BaseCache();
this.json = new BaseCache();
this.xml = new BaseCache();
this.physics = new BaseCache();
this.tilemap = new BaseCache();
this.binary = new BaseCache();
this.bitmapFont = new BaseCache();
this.shader = new BaseCache();
this.custom = {};
};
Cache.prototype.constructor = Cache;
Cache.prototype = {
// Add your own custom Cache entry, available under Cache.custom.key
addCustom: function (key)
{
if (!this.custom.hasOwnProperty(key))
{
this.custom[key] = new BaseCache();
return this.custom[key];
}
}
};
module.exports = Cache;

View file

@ -1,12 +0,0 @@
var CacheEntry = function (key, url, data)
{
this.key = key;
this.url = url;
this.data = data;
};
CacheEntry.prototype.constructor = CacheEntry;
module.exports = CacheEntry;

41
v3/src/cache/GlobalCache.js vendored Normal file
View file

@ -0,0 +1,41 @@
var BaseCache = require('./BaseCache');
var Class = require('../utils/Class');
// Phaser.Cache.GlobalCache
var GlobalCache = new Class({
initialize:
function GlobalCache (game)
{
this.game = game;
this.sound = new BaseCache();
this.video = new BaseCache();
this.text = new BaseCache();
this.json = new BaseCache();
this.xml = new BaseCache();
this.physics = new BaseCache();
this.tilemap = new BaseCache();
this.binary = new BaseCache();
this.bitmapFont = new BaseCache();
this.shader = new BaseCache();
this.custom = {};
},
// Add your own custom Cache entry, available under Cache.custom.key
addCustom: function (key)
{
if (!this.custom.hasOwnProperty(key))
{
this.custom[key] = new BaseCache();
return this.custom[key];
}
}
});
module.exports = GlobalCache;

View file

@ -1,15 +1,21 @@
var Class = require('../../utils/Class');
var Event = require('../../events/Event');
var CacheAddEvent = function (cache, key, data)
{
Event.call(this, 'CACHE_ADD_EVENT');
var CacheAddEvent = new Class({
this.cache = cache;
this.key = key;
this.data = data;
};
Extends: Event,
CacheAddEvent.prototype = Object.create(Event.prototype);
CacheAddEvent.prototype.constructor = CacheAddEvent;
initialize:
function CacheAddEvent (cache, key, data)
{
Event.call(this, 'CACHE_ADD_EVENT');
this.cache = cache;
this.key = key;
this.data = data;
}
});
module.exports = CacheAddEvent;

View file

@ -1,15 +1,21 @@
var Class = require('../../utils/Class');
var Event = require('../../events/Event');
var CacheRemoveEvent = function (cache, key, data)
{
Event.call(this, 'CACHE_ADD_EVENT');
var CacheRemoveEvent = new Class({
this.cache = cache;
this.key = key;
this.data = data;
};
Extends: Event,
CacheRemoveEvent.prototype = Object.create(Event.prototype);
CacheRemoveEvent.prototype.constructor = CacheRemoveEvent;
initialize:
function CacheRemoveEvent (cache, key, data)
{
Event.call(this, 'CACHE_REMOVE_EVENT');
this.cache = cache;
this.key = key;
this.data = data;
}
});
module.exports = CacheRemoveEvent;

View file

@ -1,58 +1,59 @@
var Class = require('../utils/Class');
var Rectangle = require('../geom/rectangle/Rectangle');
var TransformMatrix = require('../components/TransformMatrix');
var ValueToColor = require('../graphics/color/ValueToColor');
var Camera = function (x, y, width, height)
{
this.name = '';
var Camera = new Class({
this.x = x;
this.y = y;
this.width = width;
this.height = height;
initialize:
this.roundPixels = false;
this.useBounds = false;
function Camera (x, y, width, height)
{
this.name = '';
this._bounds = new Rectangle();
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.scrollX = 0.0;
this.scrollY = 0.0;
this.zoom = 1.0;
this.rotation = 0.0;
this.matrix = new TransformMatrix(1, 0, 0, 1, 0, 0);
this.roundPixels = false;
this.useBounds = false;
// shake
this._shakeDuration = 0.0;
this._shakeIntensity = 0.0;
this._shakeOffsetX = 0.0;
this._shakeOffsetY = 0.0;
this._bounds = new Rectangle();
// fade
this._fadeDuration = 0.0;
this._fadeRed = 0.0;
this._fadeGreen = 0.0;
this._fadeBlue = 0.0;
this._fadeAlpha = 0.0;
this.scrollX = 0.0;
this.scrollY = 0.0;
this.zoom = 1.0;
this.rotation = 0.0;
this.matrix = new TransformMatrix(1, 0, 0, 1, 0, 0);
// flash
this._flashDuration = 0.0;
this._flashRed = 1.0;
this._flashGreen = 1.0;
this._flashBlue = 1.0;
this._flashAlpha = 0.0;
// shake
this._shakeDuration = 0.0;
this._shakeIntensity = 0.0;
this._shakeOffsetX = 0.0;
this._shakeOffsetY = 0.0;
// origin
this._follow = null;
// fade
this._fadeDuration = 0.0;
this._fadeRed = 0.0;
this._fadeGreen = 0.0;
this._fadeBlue = 0.0;
this._fadeAlpha = 0.0;
this.clearBeforeRender = true;
this.backgroundColor = ValueToColor('rgba(0,0,0,0)');
this.transparent = true;
};
// flash
this._flashDuration = 0.0;
this._flashRed = 1.0;
this._flashGreen = 1.0;
this._flashBlue = 1.0;
this._flashAlpha = 0.0;
Camera.prototype.constructor = Camera;
// origin
this._follow = null;
Camera.prototype = {
this.clearBeforeRender = true;
this.backgroundColor = ValueToColor('rgba(0,0,0,0)');
this.transparent = true;
},
setBackgroundColor: function (color)
{
@ -352,6 +353,6 @@ Camera.prototype = {
this.state = undefined;
}
};
});
module.exports = Camera;

View file

@ -1,3 +1,4 @@
var Class = require('../utils/Class');
var GetValue = require('../utils/object/GetValue');
// var camControl = new CameraControl({
@ -7,34 +8,34 @@ var GetValue = require('../utils/object/GetValue');
// speed: float OR { x: 0, y: 0 }
// })
var KeyControl = function (config)
{
this.camera = GetValue(config, 'camera', null);
var KeyControl = new Class({
this.left = GetValue(config, 'left', null);
this.right = GetValue(config, 'right', null);
this.up = GetValue(config, 'up', null);
this.down = GetValue(config, 'down', null);
initialize:
var speed = GetValue(config, 'speed', null);
if (typeof speed === 'number')
function KeyControl (config)
{
this.speedX = speed;
this.speedY = speed;
}
else
{
this.speedX = GetValue(config, 'speed.x', 0);
this.speedY = GetValue(config, 'speed.y', 0);
}
this.camera = GetValue(config, 'camera', null);
this.active = (this.camera !== null);
};
this.left = GetValue(config, 'left', null);
this.right = GetValue(config, 'right', null);
this.up = GetValue(config, 'up', null);
this.down = GetValue(config, 'down', null);
KeyControl.prototype.constructor = KeyControl;
var speed = GetValue(config, 'speed', null);
KeyControl.prototype = {
if (typeof speed === 'number')
{
this.speedX = speed;
this.speedY = speed;
}
else
{
this.speedX = GetValue(config, 'speed.x', 0);
this.speedY = GetValue(config, 'speed.y', 0);
}
this.active = (this.camera !== null);
},
start: function ()
{
@ -85,6 +86,7 @@ KeyControl.prototype = {
this.up = null;
this.down = null;
}
};
});
module.exports = KeyControl;

View file

@ -1,3 +1,4 @@
var Class = require('../utils/Class');
var GetValue = require('../utils/object/GetValue');
// var camControl = new SmoothedKeyControl({
@ -9,63 +10,63 @@ var GetValue = require('../utils/object/GetValue');
// maxSpeed: float || { x: 0, y: 0 }
// })
var SmoothedKeyControl = function (config)
{
this.camera = GetValue(config, 'camera', null);
var SmoothedKeyControl = new Class({
this.left = GetValue(config, 'left', null);
this.right = GetValue(config, 'right', null);
this.up = GetValue(config, 'up', null);
this.down = GetValue(config, 'down', null);
initialize:
var accel = GetValue(config, 'acceleration', null);
if (typeof accel === 'number')
function SmoothedKeyControl (config)
{
this.accelX = accel;
this.accelY = accel;
}
else
{
this.accelX = GetValue(config, 'acceleration.x', 0);
this.accelY = GetValue(config, 'acceleration.y', 0);
}
this.camera = GetValue(config, 'camera', null);
var drag = GetValue(config, 'drag', null);
this.left = GetValue(config, 'left', null);
this.right = GetValue(config, 'right', null);
this.up = GetValue(config, 'up', null);
this.down = GetValue(config, 'down', null);
if (typeof drag === 'number')
{
this.dragX = drag;
this.dragY = drag;
}
else
{
this.dragX = GetValue(config, 'drag.x', 0);
this.dragY = GetValue(config, 'drag.y', 0);
}
var accel = GetValue(config, 'acceleration', null);
var maxSpeed = GetValue(config, 'maxSpeed', null);
if (typeof accel === 'number')
{
this.accelX = accel;
this.accelY = accel;
}
else
{
this.accelX = GetValue(config, 'acceleration.x', 0);
this.accelY = GetValue(config, 'acceleration.y', 0);
}
if (typeof maxSpeed === 'number')
{
this.maxSpeedX = maxSpeed;
this.maxSpeedY = maxSpeed;
}
else
{
this.maxSpeedX = GetValue(config, 'maxSpeed.x', 0);
this.maxSpeedY = GetValue(config, 'maxSpeed.y', 0);
}
var drag = GetValue(config, 'drag', null);
this._speedX = 0;
this._speedY = 0;
if (typeof drag === 'number')
{
this.dragX = drag;
this.dragY = drag;
}
else
{
this.dragX = GetValue(config, 'drag.x', 0);
this.dragY = GetValue(config, 'drag.y', 0);
}
this.active = (this.camera !== null);
};
var maxSpeed = GetValue(config, 'maxSpeed', null);
SmoothedKeyControl.prototype.constructor = SmoothedKeyControl;
if (typeof maxSpeed === 'number')
{
this.maxSpeedX = maxSpeed;
this.maxSpeedY = maxSpeed;
}
else
{
this.maxSpeedX = GetValue(config, 'maxSpeed.x', 0);
this.maxSpeedY = GetValue(config, 'maxSpeed.y', 0);
}
SmoothedKeyControl.prototype = {
this._speedX = 0;
this._speedY = 0;
this.active = (this.camera !== null);
},
start: function ()
{
@ -190,6 +191,7 @@ SmoothedKeyControl.prototype = {
this.up = null;
this.down = null;
}
};
});
module.exports = SmoothedKeyControl;

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: '4167f220-5d44-11e7-9b99-3f0e61c75797'
build: 'f62eb230-5da2-11e7-9471-651c81b97fd3'
};
module.exports = CHECKSUM;

View file

@ -1,28 +1,19 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2016 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Class = require('../utils/Class');
/**
* The Children Component features quick access to Group sorting related methods.
*
* @class
*/
var Children = function (gameObject)
{
this.gameObject = gameObject;
var Children = new Class({
// The objects that belong to this collection.
// The equivalent of the old `Sprite.children` array.
this.list = [];
initialize:
this.position = 0;
};
function Children (owner)
{
this.owner = owner;
Children.prototype.constructor = Children;
// The objects that belong to this collection.
// The equivalent of the old `Sprite.children` array.
this.list = [];
Children.prototype = {
this.position = 0;
},
add: function (child)
{
@ -35,7 +26,7 @@ Children.prototype = {
child.parent.children.remove(child);
}
child.parent = this.gameObject;
child.parent = this.owner;
this.list.push(child);
@ -587,22 +578,10 @@ Children.prototype = {
}
return newParent;
}
},
};
Object.defineProperties(Children.prototype, {
/**
* Returns the first item and resets the cursor to the start.
*
* @name Phaser.ArraySet#first
* @property {any} first
*/
length: {
enumerable: true,
get: function ()
{
return this.list.length;
@ -610,16 +589,8 @@ Object.defineProperties(Children.prototype, {
},
/**
* Returns the first item and resets the cursor to the start.
*
* @name Phaser.ArraySet#first
* @property {any} first
*/
first: {
enumerable: true,
get: function ()
{
this.position = 0;
@ -636,16 +607,8 @@ Object.defineProperties(Children.prototype, {
},
/**
* Returns the last item and resets the cursor to the end.
*
* @name Phaser.ArraySet#last
* @property {any} last
*/
last: {
enumerable: true,
get: function ()
{
if (this.list.length > 0)
@ -662,16 +625,8 @@ Object.defineProperties(Children.prototype, {
},
/**
* Returns the next item (based on the cursor) and advances the cursor.
*
* @name Phaser.ArraySet#next
* @property {any} next
*/
next: {
enumerable: true,
get: function ()
{
if (this.position < this.list.length)
@ -688,16 +643,8 @@ Object.defineProperties(Children.prototype, {
},
/**
* Returns the previous item (based on the cursor) and retreats the cursor.
*
* @name Phaser.ArraySet#previous
* @property {any} previous
*/
previous: {
enumerable: true,
get: function ()
{
if (this.position > 0)

View file

@ -16,8 +16,6 @@ var Color = function (gameObject)
this.state = gameObject.state;
this._dirty = false;
this._alpha = 1;
this._worldAlpha = 1;
@ -64,7 +62,7 @@ Color.prototype = {
this._a = (alpha) ? alpha : 1;
}
this.dirty = true;
this.update();
},
clearTint: function ()
@ -90,14 +88,12 @@ Color.prototype = {
this._hasTint = true;
this.dirty = true;
this.update();
},
// Called by the Dirty Manager
update: function ()
{
this._dirty = false;
if (this._hasBackground)
{
this._rgba = 'rgba(' + this._r + ',' + this._g + ',' + this._b + ',' + this._a + ')';
@ -105,7 +101,6 @@ Color.prototype = {
}
// Tint mults?
},
getColor: function (value)
@ -131,34 +126,6 @@ Color.prototype = {
Object.defineProperties(Color.prototype, {
dirty: {
enumerable: true,
get: function ()
{
return this._dirty;
},
set: function (value)
{
if (value)
{
if (!this._dirty)
{
this._dirty = true;
this.state.sys.updates.add(this);
}
}
else
{
this._dirty = false;
}
}
},
tintTopLeft: {
enumerable: true,
@ -172,7 +139,7 @@ Object.defineProperties(Color.prototype, {
{
this._tint.topLeft = value;
this._glTint.topLeft = this.getColor(value);
this.dirty = true;
this.update();
}
},
@ -190,7 +157,7 @@ Object.defineProperties(Color.prototype, {
{
this._tint.topRight = value;
this._glTint.topRight = this.getColor(value);
this.dirty = true;
this.update();
}
},
@ -208,7 +175,7 @@ Object.defineProperties(Color.prototype, {
{
this._tint.bottomLeft = value;
this._glTint.bottomLeft = this.getColor(value);
this.dirty = true;
this.update();
}
},
@ -226,7 +193,7 @@ Object.defineProperties(Color.prototype, {
{
this._tint.bottomRight = value;
this._glTint.bottomRight = this.getColor(value);
this.dirty = true;
this.update();
}
},
@ -261,7 +228,7 @@ Object.defineProperties(Color.prototype, {
if (value !== this._alpha)
{
this._alpha = value;
this.dirty = true;
this.update();
}
}
@ -281,7 +248,7 @@ Object.defineProperties(Color.prototype, {
if (value !== this._blendMode && value >= 0 && value <= 16)
{
this._blendMode = value;
this.dirty = true;
this.update();
}
}
@ -323,7 +290,7 @@ Object.defineProperties(Color.prototype, {
{
this._a = value;
this._hasBackground = true;
this.dirty = true;
this.update();
}
}
@ -344,7 +311,7 @@ Object.defineProperties(Color.prototype, {
{
this._r = value | 0;
this._hasBackground = true;
this.dirty = true;
this.update();
}
}
@ -365,7 +332,7 @@ Object.defineProperties(Color.prototype, {
{
this._g = value | 0;
this._hasBackground = true;
this.dirty = true;
this.update();
}
}
@ -386,7 +353,7 @@ Object.defineProperties(Color.prototype, {
{
this._b = value | 0;
this._hasBackground = true;
this.dirty = true;
this.update();
}
}

View file

@ -1,35 +1,29 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2016 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Class = require('../utils/Class');
var Event = require('../events/Event');
var EventDispatcher = require('../events/EventDispatcher');
/**
* The Data Component features a means to store pieces of data specific to a Game Object,
* search it, query it, and retrieve it.
*
* @class
*/
var Data = function (parent)
{
this.parent = parent;
var Data = new Class({
this.events = new EventDispatcher();
initialize:
this.list = {};
function Data (parent)
{
this.parent = parent;
this._beforeCallbacks = {};
this._afterCallbacks = {};
this.events = new EventDispatcher();
this._frozen = false;
};
this.list = {};
Data.prototype.constructor = Data;
this._beforeCallbacks = {};
this._afterCallbacks = {};
Data.prototype = {
this._frozen = false;
},
// Retrieves the value for the given key, or undefined if it doesn't exist.
get: function (key)
@ -238,11 +232,7 @@ Data.prototype = {
}
this._frozen = false;
}
};
Object.defineProperties(Data.prototype, {
},
/**
* Freeze this Data component, so no changes can be written to it.
@ -252,8 +242,6 @@ Object.defineProperties(Data.prototype, {
*/
freeze: {
enumerable: true,
get: function ()
{
return this._frozen;
@ -268,8 +256,6 @@ Object.defineProperties(Data.prototype, {
count: {
enumerable: true,
get: function ()
{
var i = 0;

View file

@ -1,240 +1,242 @@
var mathCos = Math.cos;
var mathSin = Math.sin;
var mathSqrt = Math.sqrt;
var mathAcos = Math.acos;
var mathAtan = Math.atan;
var Class = require('../utils/Class');
var TransformMatrix = function (a, b, c, d, tx, ty)
{
a = typeof a === 'number' ? a : 1;
b = typeof b === 'number' ? b : 0;
c = typeof c === 'number' ? c : 0;
d = typeof d === 'number' ? d : 1;
tx = typeof tx === 'number' ? tx : 0;
ty = typeof ty === 'number' ? ty : 0;
var TransformMatrix = new Class({
this.matrix = new Float32Array([a, b, c, d, tx, ty, 0, 0, 1]);
initialize:
this.decomposedMatrix = {
translateX: 0,
translateY: 0,
scaleX: 1,
scaleY: 1,
rotation: 0
};
};
function TransformMatrix (a, b, c, d, tx, ty)
{
if (a === undefined) { a = 1; }
if (b === undefined) { b = 0; }
if (c === undefined) { c = 0; }
if (d === undefined) { d = 1; }
if (tx === undefined) { tx = 0; }
if (ty === undefined) { ty = 0; }
TransformMatrix.prototype.loadIdentity = function ()
{
var matrix = this.matrix;
this.matrix = new Float32Array([ a, b, c, d, tx, ty, 0, 0, 1 ]);
matrix[0] = 1;
matrix[1] = 0;
matrix[2] = 0;
matrix[3] = 1;
matrix[4] = 0;
matrix[5] = 0;
this.decomposedMatrix = {
translateX: 0,
translateY: 0,
scaleX: 1,
scaleY: 1,
rotation: 0
};
},
return this;
};
loadIdentity: function ()
{
var matrix = this.matrix;
TransformMatrix.prototype.translate = function (x, y)
{
var matrix = this.matrix;
matrix[0] = 1;
matrix[1] = 0;
matrix[2] = 0;
matrix[3] = 1;
matrix[4] = 0;
matrix[5] = 0;
matrix[4] = matrix[0] * x + matrix[2] * y + matrix[4];
matrix[5] = matrix[1] * x + matrix[3] * y + matrix[5];
return this;
},
return this;
};
translate: function (x, y)
{
var matrix = this.matrix;
TransformMatrix.prototype.scale = function (x, y)
{
var matrix = this.matrix;
matrix[4] = matrix[0] * x + matrix[2] * y + matrix[4];
matrix[5] = matrix[1] * x + matrix[3] * y + matrix[5];
matrix[0] = matrix[0] * x;
matrix[1] = matrix[1] * x;
matrix[2] = matrix[2] * y;
matrix[3] = matrix[3] * y;
return this;
},
return this;
};
scale: function (x, y)
{
var matrix = this.matrix;
TransformMatrix.prototype.rotate = function (radian)
{
var radianSin = mathSin(radian);
var radianCos = mathCos(radian);
matrix[0] *= x;
matrix[1] *= x;
matrix[2] *= y;
matrix[3] *= y;
return this.transform(radianCos, -radianSin, radianSin, radianCos, 0, 0);
};
return this;
},
TransformMatrix.prototype.multiply = function (otherMatrix)
{
var matrix = this.matrix;
rotate: function (radian)
{
var radianSin = Math.sin(radian);
var radianCos = Math.cos(radian);
var a0 = matrix[0];
var b0 = matrix[1];
var c0 = matrix[2];
var d0 = matrix[3];
var tx0 = matrix[4];
var ty0 = matrix[5];
return this.transform(radianCos, -radianSin, radianSin, radianCos, 0, 0);
},
var a1 = otherMatrix[0];
var b1 = otherMatrix[1];
var c1 = otherMatrix[2];
var d1 = otherMatrix[3];
var tx1 = otherMatrix[4];
var ty1 = otherMatrix[5];
multiply: function (otherMatrix)
{
var matrix = this.matrix;
matrix[0] = a1 * a0 + b1 * c0;
matrix[1] = a1 * b0 + b1 * d0;
matrix[2] = c1 * a0 + d1 * c0;
matrix[3] = c1 * b0 + d1 * d0;
matrix[4] = tx1 * a0 + ty1 * c0 + tx0;
matrix[5] = tx1 * b0 + ty1 * d0 + ty0;
var a0 = matrix[0];
var b0 = matrix[1];
var c0 = matrix[2];
var d0 = matrix[3];
var tx0 = matrix[4];
var ty0 = matrix[5];
return this;
};
var a1 = otherMatrix[0];
var b1 = otherMatrix[1];
var c1 = otherMatrix[2];
var d1 = otherMatrix[3];
var tx1 = otherMatrix[4];
var ty1 = otherMatrix[5];
TransformMatrix.prototype.transform = function (a, b, c, d, tx, ty)
{
var matrix = this.matrix;
matrix[0] = a1 * a0 + b1 * c0;
matrix[1] = a1 * b0 + b1 * d0;
matrix[2] = c1 * a0 + d1 * c0;
matrix[3] = c1 * b0 + d1 * d0;
matrix[4] = tx1 * a0 + ty1 * c0 + tx0;
matrix[5] = tx1 * b0 + ty1 * d0 + ty0;
var a0 = matrix[0];
var b0 = matrix[1];
var c0 = matrix[2];
var d0 = matrix[3];
var tx0 = matrix[4];
var ty0 = matrix[5];
return this;
},
matrix[0] = a * a0 + b * c0;
matrix[1] = a * b0 + b * d0;
matrix[2] = c * a0 + d * c0;
matrix[3] = c * b0 + d * d0;
matrix[4] = tx * a0 + ty * c0 + tx0;
matrix[5] = tx * b0 + ty * d0 + ty0;
transform: function (a, b, c, d, tx, ty)
{
var matrix = this.matrix;
return this;
};
var a0 = matrix[0];
var b0 = matrix[1];
var c0 = matrix[2];
var d0 = matrix[3];
var tx0 = matrix[4];
var ty0 = matrix[5];
TransformMatrix.prototype.transformPoint = function (x, y, point)
{
if (point === undefined) { point = { x: 0, y: 0 }; }
matrix[0] = a * a0 + b * c0;
matrix[1] = a * b0 + b * d0;
matrix[2] = c * a0 + d * c0;
matrix[3] = c * b0 + d * d0;
matrix[4] = tx * a0 + ty * c0 + tx0;
matrix[5] = tx * b0 + ty * d0 + ty0;
var matrix = this.matrix;
return this;
},
var a = matrix[0];
var b = matrix[1];
var c = matrix[2];
var d = matrix[3];
var tx = matrix[4];
var ty = matrix[5];
transformPoint: function (x, y, point)
{
if (point === undefined) { point = { x: 0, y: 0 }; }
point.x = x * a + y * c + tx;
point.y = x * b + y * d + ty;
var matrix = this.matrix;
return point;
};
var a = matrix[0];
var b = matrix[1];
var c = matrix[2];
var d = matrix[3];
var tx = matrix[4];
var ty = matrix[5];
TransformMatrix.prototype.invert = function ()
{
var matrix = this.matrix;
point.x = x * a + y * c + tx;
point.y = x * b + y * d + ty;
var a = matrix[0];
var b = matrix[1];
var c = matrix[2];
var d = matrix[3];
var tx = matrix[4];
var ty = matrix[5];
return point;
},
var n = a * d - b * c;
invert: function ()
{
var matrix = this.matrix;
matrix[0] = d / n;
matrix[1] = -b / n;
matrix[2] = -c / n;
matrix[3] = a / n;
matrix[4] = (c * ty - d * tx) / n;
matrix[5] = -(a * ty - b * tx) / n;
var a = matrix[0];
var b = matrix[1];
var c = matrix[2];
var d = matrix[3];
var tx = matrix[4];
var ty = matrix[5];
return this;
};
var n = a * d - b * c;
TransformMatrix.prototype.setTransform = function (a, b, c, d, tx, ty)
{
var matrix = this.matrix;
matrix[0] = d / n;
matrix[1] = -b / n;
matrix[2] = -c / n;
matrix[3] = a / n;
matrix[4] = (c * ty - d * tx) / n;
matrix[5] = -(a * ty - b * tx) / n;
matrix[0] = a;
matrix[1] = b;
matrix[2] = c;
matrix[3] = d;
matrix[4] = tx;
matrix[5] = ty;
return this;
},
return this;
};
setTransform: function (a, b, c, d, tx, ty)
{
var matrix = this.matrix;
TransformMatrix.prototype.decomposeMatrix = function ()
{
var decomposedMatrix = this.decomposedMatrix;
matrix[0] = a;
matrix[1] = b;
matrix[2] = c;
matrix[3] = d;
matrix[4] = tx;
matrix[5] = ty;
var matrix = this.matrix;
return this;
},
var a = matrix[0];
var b = matrix[1];
var c = matrix[2];
var d = matrix[3];
decomposeMatrix: function ()
{
var decomposedMatrix = this.decomposedMatrix;
var a2 = a * a;
var b2 = b * b;
var c2 = c * c;
var d2 = d * d;
var matrix = this.matrix;
var sx = mathSqrt(a2 + c2);
var sy = mathSqrt(b2 + d2);
var a = matrix[0];
var b = matrix[1];
var c = matrix[2];
var d = matrix[3];
decomposedMatrix.translateX = matrix[4];
decomposedMatrix.translateY = matrix[5];
var a2 = a * a;
var b2 = b * b;
var c2 = c * c;
var d2 = d * d;
decomposedMatrix.scaleX = sx;
decomposedMatrix.scaleY = sy;
var sx = Math.sqrt(a2 + c2);
var sy = Math.sqrt(b2 + d2);
decomposedMatrix.rotation = mathAcos(a / sx) * (mathAtan(-c / a) < 0 ? -1 : 1);
decomposedMatrix.translateX = matrix[4];
decomposedMatrix.translateY = matrix[5];
return decomposedMatrix;
};
decomposedMatrix.scaleX = sx;
decomposedMatrix.scaleY = sy;
/* identity + translate + rotate + scale */
TransformMatrix.prototype.applyITRS = function (x, y, rotation, scaleX, scaleY)
{
var matrix = this.matrix;
decomposedMatrix.rotation = Math.acos(a / sx) * (Math.atan(-c / a) < 0 ? -1 : 1);
var a = 1;
var b = 0;
var c = 0;
var d = 1;
var tx = 0;
var ty = 0;
return decomposedMatrix;
},
var sr = mathSin(rotation);
var cr = mathCos(rotation);
/* identity + translate + rotate + scale */
applyITRS: function (x, y, rotation, scaleX, scaleY)
{
var matrix = this.matrix;
// Translate
matrix[4] = a * x + c * y + tx;
matrix[5] = b * x + d * y + ty;
var a = 1;
var b = 0;
var c = 0;
var d = 1;
var tx = 0;
var ty = 0;
// Rotate
matrix[0] = cr * a + -sr * c;
matrix[1] = cr * b + -sr * d;
matrix[2] = sr * a + cr * c;
matrix[3] = sr * b + cr * d;
var sr = Math.sin(rotation);
var cr = Math.cos(rotation);
// Scale
matrix[0] = matrix[0] * scaleX;
matrix[1] = matrix[1] * scaleX;
matrix[2] = matrix[2] * scaleY;
matrix[3] = matrix[3] * scaleY;
// Translate
matrix[4] = a * x + c * y + tx;
matrix[5] = b * x + d * y + ty;
return this;
};
// Rotate
matrix[0] = cr * a + -sr * c;
matrix[1] = cr * b + -sr * d;
matrix[2] = sr * a + cr * c;
matrix[3] = sr * b + cr * d;
// Scale
matrix[0] = matrix[0] * scaleX;
matrix[1] = matrix[1] * scaleX;
matrix[2] = matrix[2] * scaleY;
matrix[3] = matrix[3] * scaleY;
return this;
}
});
module.exports = TransformMatrix;

View file

@ -16,7 +16,6 @@
* @param {height} Height of the mask data array
* @param {mirrorX} A boolean describing whether the mask should be mirrored on the x axis
* @param {mirrorY} A boolean describing whether the mask should be mirrored on the y axis
*/
export default function Mask (data, width, height, mirrorX = true, mirrorY = true) {
return {
@ -28,3 +27,4 @@ export default function Mask (data, width, height, mirrorX = true, mirrorY = tru
};
}
*/

View file

@ -12,6 +12,8 @@ var Video = require('./Video');
var Fullscreen = require('./Fullscreen');
var CanvasFeatures = require('./CanvasFeatures');
// Phaser.Device
module.exports = {
OS: OS,

View file

@ -1,16 +1,18 @@
var Event = function (type)
{
this.type = type;
var Class = require('../utils/Class');
// The element that initiated the event.
this.target;
var Event = new Class({
this._propagate = true;
};
initialize:
Event.prototype.constructor = Event;
function Event (type)
{
this.type = type;
Event.prototype = {
// The element that initiated the event.
this.target;
this._propagate = true;
},
reset: function (target)
{
@ -24,6 +26,6 @@ Event.prototype = {
this._propagate = false;
}
};
});
module.exports = Event;

View file

@ -1,17 +1,18 @@
var Class = require('../utils/Class');
var CONST = require('./const');
var EventListener = require('./EventListener');
var EventBinding = function (dispatcher, type)
{
this.dispatcher = dispatcher;
this.type = type;
this.state = CONST.DISPATCHER_IDLE;
this.active = [];
};
var EventBinding = new Class({
EventBinding.prototype.constructor = EventBinding;
initialize:
EventBinding.prototype = {
function EventBinding (dispatcher, type)
{
this.dispatcher = dispatcher;
this.type = type;
this.state = CONST.DISPATCHER_IDLE;
this.active = [];
},
total: function ()
{
@ -263,6 +264,6 @@ EventBinding.prototype = {
this.state = CONST.DISPATCHER_DESTROYED;
}
};
});
module.exports = EventBinding;

View file

@ -1,15 +1,16 @@
var Class = require('../utils/Class');
var EventBinding = require('./EventBinding');
var EventDispatcher = function ()
{
this.bindings = {};
this.filters = [];
this.hasFilters = false;
};
var EventDispatcher = new Class({
EventDispatcher.prototype.constructor = EventDispatcher;
initialize:
EventDispatcher.prototype = {
function EventDispatcher ()
{
this.bindings = {};
this.filters = [];
this.hasFilters = false;
},
getBinding: function (type)
{
@ -213,6 +214,6 @@ EventDispatcher.prototype = {
this.removeAllFilters();
}
};
});
module.exports = EventDispatcher;

View file

@ -1,20 +1,22 @@
var Circle = function (x, y, radius)
{
if (x === undefined) { x = 0; }
if (y === undefined) { y = 0; }
if (radius === undefined) { radius = 0; }
var Class = require('../../utils/Class');
this.x = x;
var Circle = new Class({
this.y = y;
initialize:
this._radius = radius;
this._diameter = radius * 2;
};
function Circle (x, y, radius)
{
if (x === undefined) { x = 0; }
if (y === undefined) { y = 0; }
if (radius === undefined) { radius = 0; }
Circle.prototype.constructor = Circle;
this.x = x;
Circle.prototype = {
this.y = y;
this._radius = radius;
this._diameter = radius * 2;
},
setTo: function (x, y, radius)
{
@ -44,16 +46,10 @@ Circle.prototype = {
isEmpty: function ()
{
return (this._radius <= 0);
}
};
Object.defineProperties(Circle.prototype, {
},
radius: {
enumerable: true,
get: function ()
{
return this._radius;
@ -69,8 +65,6 @@ Object.defineProperties(Circle.prototype, {
diameter: {
enumerable: true,
get: function ()
{
return this._diameter;
@ -86,8 +80,6 @@ Object.defineProperties(Circle.prototype, {
left: {
enumerable: true,
get: function ()
{
return this.x - this._radius;
@ -102,8 +94,6 @@ Object.defineProperties(Circle.prototype, {
right: {
enumerable: true,
get: function ()
{
return this.x + this._radius;
@ -118,8 +108,6 @@ Object.defineProperties(Circle.prototype, {
top: {
enumerable: true,
get: function ()
{
return this.y - this._radius;
@ -134,8 +122,6 @@ Object.defineProperties(Circle.prototype, {
bottom: {
enumerable: true,
get: function ()
{
return this.y + this._radius;

View file

@ -1,22 +1,24 @@
var Ellipse = function (x, y, width, height)
{
if (x === undefined) { x = 0; }
if (y === undefined) { y = 0; }
if (width === undefined) { width = 0; }
if (height === undefined) { height = 0; }
var Class = require('../../utils/Class');
this.x = x;
var Ellipse = new Class({
this.y = y;
initialize:
this.width = width;
function Ellipse (x, y, width, height)
{
if (x === undefined) { x = 0; }
if (y === undefined) { y = 0; }
if (width === undefined) { width = 0; }
if (height === undefined) { height = 0; }
this.height = height;
};
this.x = x;
Ellipse.prototype.constructor = Ellipse;
this.y = y;
Ellipse.prototype = {
this.width = width;
this.height = height;
},
setTo: function (x, y, width, height)
{
@ -68,16 +70,10 @@ Ellipse.prototype = {
getMajorRadius: function ()
{
return Math.max(this.width, this.height) / 2;
}
};
Object.defineProperties(Ellipse.prototype, {
},
left: {
enumerable: true,
get: function ()
{
return this.x;
@ -101,8 +97,6 @@ Object.defineProperties(Ellipse.prototype, {
right: {
enumerable: true,
get: function ()
{
return this.x + this.width;
@ -124,8 +118,6 @@ Object.defineProperties(Ellipse.prototype, {
top: {
enumerable: true,
get: function ()
{
return this.y;
@ -148,8 +140,6 @@ Object.defineProperties(Ellipse.prototype, {
bottom: {
enumerable: true,
get: function ()
{
return this.y + this.height;

View file

@ -1,18 +1,20 @@
var Class = require('../../utils/Class');
// Defines a Line segment, a part of a line between two endpoints
var Line = function (x1, y1, x2, y2)
{
this.x1 = 0;
this.y1 = 0;
this.x2 = 0;
this.y2 = 0;
var Line = new Class({
this.setTo(x1, y1, x2, y2);
};
initialize:
Line.prototype.constructor = Line;
function Line (x1, y1, x2, y2)
{
this.x1 = 0;
this.y1 = 0;
this.x2 = 0;
this.y2 = 0;
Line.prototype = {
this.setTo(x1, y1, x2, y2);
},
setTo: function (x1, y1, x2, y2)
{
@ -38,16 +40,10 @@ Line.prototype = {
getPointB: function ()
{
return { x1: this.x2, y1: this.y2 };
}
};
Object.defineProperties(Line.prototype, {
},
left: {
enumerable: true,
get: function ()
{
return Math.min(this.x1, this.x2);
@ -69,8 +65,6 @@ Object.defineProperties(Line.prototype, {
right: {
enumerable: true,
get: function ()
{
return Math.max(this.x1, this.x2);
@ -92,8 +86,6 @@ Object.defineProperties(Line.prototype, {
top: {
enumerable: true,
get: function ()
{
return Math.min(this.y1, this.y2);
@ -115,8 +107,6 @@ Object.defineProperties(Line.prototype, {
bottom: {
enumerable: true,
get: function ()
{
return Math.max(this.y1, this.y2);

View file

@ -1,16 +1,18 @@
var Point = function (x, y)
{
if (x === undefined) { x = 0; }
if (y === undefined) { y = x; }
var Class = require('../../utils/Class');
this.x = x;
var Point = new Class({
this.y = y;
};
initialize:
Point.prototype.constructor = Point;
function Point (x, y)
{
if (x === undefined) { x = 0; }
if (y === undefined) { y = x; }
Point.prototype = {
this.x = x;
this.y = y;
},
setTo: function (x, y)
{
@ -23,6 +25,6 @@ Point.prototype = {
return this;
}
};
});
module.exports = Point;

View file

@ -1,24 +1,26 @@
var Polygon = function (points)
{
/**
* @property {number} area - The area of this Polygon.
*/
this.area = 0;
var Class = require('../../utils/Class');
/**
* @property {array} points - An array of number pair objects that make up this polygon. I.e. [ {x,y}, {x,y}, {x,y} ]
*/
this.points = [];
var Polygon = new Class({
if (points)
initialize:
function Polygon (points)
{
this.setTo(points);
}
};
/**
* @property {number} area - The area of this Polygon.
*/
this.area = 0;
Polygon.prototype.constructor = Polygon;
/**
* @property {array} points - An array of number pair objects that make up this polygon. I.e. [ {x,y}, {x,y}, {x,y} ]
*/
this.points = [];
Polygon.prototype = {
if (points)
{
this.setTo(points);
}
},
/**
* Sets this Polygon to the given points.
@ -149,6 +151,6 @@ Polygon.prototype = {
return this.area;
}
};
});
module.exports = Polygon;

View file

@ -1,26 +1,27 @@
var Class = require('../../utils/Class');
// Encapsulates a 2D rectangle defined by its corner point in the top-left
// and its extends in x (width) and y (height)
var Rectangle = function (x, y, width, height)
{
if (x === undefined) { x = 0; }
if (y === undefined) { y = 0; }
if (width === undefined) { width = 0; }
if (height === undefined) { height = 0; }
var Rectangle = new Class({
this.x = x;
initialize:
this.y = y;
function Rectangle (x, y, width, height)
{
if (x === undefined) { x = 0; }
if (y === undefined) { y = 0; }
if (width === undefined) { width = 0; }
if (height === undefined) { height = 0; }
this.width = width;
this.x = x;
this.height = height;
};
this.y = y;
Rectangle.prototype.constructor = Rectangle;
this.width = width;
Rectangle.prototype = {
this.height = height;
},
setTo: function (x, y, width, height)
{
@ -84,16 +85,10 @@ Rectangle.prototype = {
getLineD: function ()
{
return { x1: this.x, y1: this.bottom, x2: this.x, y2: this.y };
}
};
Object.defineProperties(Rectangle.prototype, {
},
left: {
enumerable: true,
get: function ()
{
return this.x;
@ -117,8 +112,6 @@ Object.defineProperties(Rectangle.prototype, {
right: {
enumerable: true,
get: function ()
{
return this.x + this.width;
@ -140,8 +133,6 @@ Object.defineProperties(Rectangle.prototype, {
top: {
enumerable: true,
get: function ()
{
return this.y;
@ -164,8 +155,6 @@ Object.defineProperties(Rectangle.prototype, {
bottom: {
enumerable: true,
get: function ()
{
return this.y + this.height;
@ -187,8 +176,6 @@ Object.defineProperties(Rectangle.prototype, {
centerX: {
enumerable: true,
get: function ()
{
return this.x + (this.width / 2);
@ -203,8 +190,6 @@ Object.defineProperties(Rectangle.prototype, {
centerY: {
enumerable: true,
get: function ()
{
return this.y + (this.height / 2);

View file

@ -1,24 +1,26 @@
var Class = require('../../utils/Class');
// A triangle is a plane created by connecting three points.
// The first two arguments specify the first point, the middle two arguments
// specify the second point, and the last two arguments specify the third point.
var Triangle = function (x1, y1, x2, y2, x3, y3)
{
this.x1 = 0;
this.y1 = 0;
var Triangle = new Class({
this.x2 = 0;
this.y2 = 0;
initialize:
this.x3 = 0;
this.y3 = 0;
function Triangle (x1, y1, x2, y2, x3, y3)
{
this.x1 = 0;
this.y1 = 0;
this.setTo(x1, y1, x2, y2, x3, y3);
};
this.x2 = 0;
this.y2 = 0;
Triangle.prototype.constructor = Triangle;
this.x3 = 0;
this.y3 = 0;
Triangle.prototype = {
this.setTo(x1, y1, x2, y2, x3, y3);
},
setTo: function (x1, y1, x2, y2, x3, y3)
{
@ -54,16 +56,10 @@ Triangle.prototype = {
getLineC: function ()
{
return { x1: this.x3, y1: this.y3, x2: this.x1, y2: this.y1 };
}
};
Object.defineProperties(Triangle.prototype, {
},
left: {
enumerable: true,
get: function ()
{
return Math.min(this.x1, this.x2, this.x3);
@ -95,8 +91,6 @@ Object.defineProperties(Triangle.prototype, {
right: {
enumerable: true,
get: function ()
{
return Math.max(this.x1, this.x2, this.x3);
@ -128,8 +122,6 @@ Object.defineProperties(Triangle.prototype, {
top: {
enumerable: true,
get: function ()
{
return Math.min(this.y1, this.y2, this.y3);
@ -161,8 +153,6 @@ Object.defineProperties(Triangle.prototype, {
bottom: {
enumerable: true,
get: function ()
{
return Math.max(this.y1, this.y2, this.y3);

View file

@ -1,33 +1,32 @@
var Class = require('../../utils/Class');
var GetColor = require('./GetColor');
var GetColor32 = require('./GetColor32');
var Color = function (red, green, blue, alpha)
{
if (red === undefined) { red = 0; }
if (green === undefined) { green = 0; }
if (blue === undefined) { blue = 0; }
if (alpha === undefined) { alpha = 255; }
var Color = new Class({
// All private
this.r = 0;
this.g = 0;
this.b = 0;
this.a = 255;
initialize:
this.gl = [ 0.0, 0.0, 0.0, 1.0 ];
function Color (red, green, blue, alpha)
{
if (red === undefined) { red = 0; }
if (green === undefined) { green = 0; }
if (blue === undefined) { blue = 0; }
if (alpha === undefined) { alpha = 255; }
this._color = 0;
this._color32 = 0;
this._rgba = '';
// All private
this.r = 0;
this.g = 0;
this.b = 0;
this.a = 255;
this.dirty = true;
this.gl = [ 0.0, 0.0, 0.0, 1.0 ];
this.setTo(red, green, blue, alpha);
};
this._color = 0;
this._color32 = 0;
this._rgba = '';
Color.prototype.constructor = Color;
Color.prototype = {
this.setTo(red, green, blue, alpha);
},
transparent: function ()
{
@ -36,8 +35,6 @@ Color.prototype = {
this.blue = 0;
this.alpha = 0;
this.dirty = true;
return this.update();
},
@ -51,8 +48,6 @@ Color.prototype = {
this.blue = blue;
this.alpha = alpha;
this.dirty = true;
return this.update();
},
@ -66,8 +61,6 @@ Color.prototype = {
this.blueGL = blue;
this.alphaGL = alpha;
this.dirty = true;
return this.update();
},
@ -82,24 +75,15 @@ Color.prototype = {
this.alpha = color.a;
}
this.dirty = true;
return this.update();
},
update: function ()
{
if (!this.dirty)
{
return this;
}
this._color = GetColor(this.r, this.g, this.b);
this._color32 = GetColor32(this.r, this.g, this.b, this.a);
this._rgba = 'rgba(' + this.r + ',' + this.g + ',' + this.b + ',' + (this.a / 255) + ')';
this.dirty = false;
return this;
},
@ -107,23 +91,12 @@ Color.prototype = {
clone: function ()
{
return new Color(this.r, this.g, this.b, this.a);
}
};
Object.defineProperties(Color.prototype, {
},
color: {
enumerable: true,
get: function ()
{
if (this.dirty)
{
this.update();
}
return this._color;
}
@ -131,15 +104,8 @@ Object.defineProperties(Color.prototype, {
color32: {
enumerable: true,
get: function ()
{
if (this.dirty)
{
this.update();
}
return this._color32;
}
@ -147,15 +113,8 @@ Object.defineProperties(Color.prototype, {
rgba: {
enumerable: true,
get: function ()
{
if (this.dirty)
{
this.update();
}
return this._rgba;
}
@ -164,8 +123,6 @@ Object.defineProperties(Color.prototype, {
// Gets and sets the red value, normalized to the 0 to 1 range
redGL: {
enumerable: true,
get: function ()
{
return this.gl[0];
@ -177,15 +134,13 @@ Object.defineProperties(Color.prototype, {
this.r = Math.floor(this.gl[0] * 255);
this.dirty = true;
this.update();
}
},
greenGL: {
enumerable: true,
get: function ()
{
return this.gl[1];
@ -197,15 +152,13 @@ Object.defineProperties(Color.prototype, {
this.g = Math.floor(this.gl[1] * 255);
this.dirty = true;
this.update();
}
},
blueGL: {
enumerable: true,
get: function ()
{
return this.gl[2];
@ -217,15 +170,13 @@ Object.defineProperties(Color.prototype, {
this.b = Math.floor(this.gl[2] * 255);
this.dirty = true;
this.update();
}
},
alphaGL: {
enumerable: true,
get: function ()
{
return this.gl[3];
@ -237,7 +188,7 @@ Object.defineProperties(Color.prototype, {
this.a = Math.floor(this.gl[3] * 255);
this.dirty = true;
this.update();
}
},
@ -245,8 +196,6 @@ Object.defineProperties(Color.prototype, {
// Gets and sets the red value, normalized to the 0 to 255 range
red: {
enumerable: true,
get: function ()
{
return this.r;
@ -260,15 +209,13 @@ Object.defineProperties(Color.prototype, {
this.gl[0] = value / 255;
this.dirty = true;
this.update();
}
},
green: {
enumerable: true,
get: function ()
{
return this.g;
@ -282,15 +229,13 @@ Object.defineProperties(Color.prototype, {
this.gl[1] = value / 255;
this.dirty = true;
this.update();
}
},
blue: {
enumerable: true,
get: function ()
{
return this.b;
@ -304,15 +249,13 @@ Object.defineProperties(Color.prototype, {
this.gl[2] = value / 255;
this.dirty = true;
this.update();
}
},
alpha: {
enumerable: true,
get: function ()
{
return this.a;
@ -326,12 +269,11 @@ Object.defineProperties(Color.prototype, {
this.gl[3] = value / 255;
this.dirty = true;
this.update();
}
},
}
});
module.exports = Color;

View file

@ -1,37 +1,38 @@
// GlobalInputManager
var Class = require('../utils/Class');
var EventDispatcher = require('../events/EventDispatcher');
var GetTransformedPoint = require('./components/GetTransformedPoint');
var Keyboard = require('./keyboard/KeyboardManager');
var Mouse = require('./mouse/MouseManager');
var MouseEvent = require('./mouse/events/');
var EventDispatcher = require('../events/EventDispatcher');
var GetTransformedPoint = require('./components/GetTransformedPoint');
var PointWithinGameObject = require('./components/PointWithinGameObject');
var TransformMatrix = require('../components/TransformMatrix');
var GlobalInputManager = function (game, gameConfig)
{
this.game = game;
var GlobalInputManager = new Class({
this.gameConfig = gameConfig;
initialize:
this.enabled = true;
function GlobalInputManager (game, config)
{
this.game = game;
this.events = new EventDispatcher();
this.config = config;
// Standard FIFO queue
this.queue = [];
this.enabled = true;
// Listeners
this.keyboard = new Keyboard(this);
this.mouse = new Mouse(this);
this.events = new EventDispatcher();
this._tempMatrix = new TransformMatrix();
this._tempPoint = { x: 0, y: 0 };
};
// Standard FIFO queue
this.queue = [];
GlobalInputManager.prototype.constructor = GlobalInputManager;
// Listeners
this.keyboard = new Keyboard(this);
this.mouse = new Mouse(this);
GlobalInputManager.prototype = {
this._tempMatrix = new TransformMatrix();
this._tempPoint = { x: 0, y: 0 };
},
/**
* The Boot handler is called by Phaser.Game when it first starts up.
@ -93,6 +94,6 @@ GlobalInputManager.prototype = {
return PointWithinGameObject(gameObject, x, y);
}
};
});
module.exports = GlobalInputManager;

View file

@ -1,6 +1,7 @@
var Class = require('../../utils/Class');
var Event = require('./events');
var KeyCodes = require('./keys/KeyCodes');
var Key = require('./keys/Key');
var KeyCodes = require('./keys/KeyCodes');
var KeyCombo = require('./combo/KeyCombo');
var ProcessKeyCombo = require('./combo/ProcessKeyCombo');
var ProcessKeyDown = require('./keys/ProcessKeyDown');
@ -20,29 +21,30 @@ var ProcessKeyUp = require('./keys/ProcessKeyUp');
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
*/
var KeyboardManager = function (inputManager)
{
this.manager = inputManager;
this.enabled = false;
var KeyboardManager = new Class({
this.target;
initialize:
this.keys = [];
function KeyboardManager (inputManager)
{
this.manager = inputManager;
this.combos = [];
this.enabled = false;
this.captures = [];
this.target;
// Standard FIFO queue
this.queue = [];
this.keys = [];
this.handler;
};
this.combos = [];
KeyboardManager.prototype.constructor = KeyboardManager;
this.captures = [];
KeyboardManager.prototype = {
// Standard FIFO queue
this.queue = [];
this.handler;
},
/**
* The Boot handler is called by Phaser.Game when it first starts up.
@ -53,7 +55,7 @@ KeyboardManager.prototype = {
*/
boot: function ()
{
var config = this.manager.gameConfig;
var config = this.manager.config;
this.enabled = config.inputKeyboard;
this.target = config.inputKeyboardEventTarget;
@ -265,6 +267,6 @@ KeyboardManager.prototype = {
}
}
};
});
module.exports = KeyboardManager;

View file

@ -1,5 +1,8 @@
// A generic Key object which can be passed to the Process functions (and so on)
// Can this become just a generic object instead of a class?
// A generic Key object which can be passed to the Process functions (and so on)
// keycode must be an integer
var Key = function (keyCode)

View file

@ -1,24 +1,26 @@
var Class = require('../../utils/Class');
// https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent
// https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
var MouseManager = function (inputManager)
{
this.manager = inputManager;
var MouseManager = new Class({
this.enabled = false;
initialize:
this.target;
function MouseManager (inputManager)
{
this.manager = inputManager;
this.handler;
};
this.enabled = false;
MouseManager.prototype.constructor = MouseManager;
this.target;
MouseManager.prototype = {
this.handler;
},
boot: function ()
{
var config = this.manager.gameConfig;
var config = this.manager.config;
this.enabled = config.inputMouse;
this.target = config.inputMouseEventTarget;
@ -62,6 +64,7 @@ MouseManager.prototype = {
this.target.removeEventListener('mousedown', this.handler);
this.target.removeEventListener('mouseup', this.handler);
}
};
});
module.exports = MouseManager;

View file

@ -1,16 +1,22 @@
var Class = require('../../../utils/Class');
var Event = require('../../../events/Event');
var MouseDownEvent = function (nativeEvent)
{
Event.call(this, 'MOUSE_DOWN_EVENT');
var MouseDownEvent = new Class({
this.data = nativeEvent;
Extends: Event,
this.x = nativeEvent.clientX;
this.y = nativeEvent.clientY;
};
initialize:
MouseDownEvent.prototype = Object.create(Event.prototype);
MouseDownEvent.prototype.constructor = MouseDownEvent;
function MouseDownEvent (nativeEvent)
{
Event.call(this, 'MOUSE_DOWN_EVENT');
this.data = nativeEvent;
this.x = nativeEvent.clientX;
this.y = nativeEvent.clientY;
}
});
module.exports = MouseDownEvent;

View file

@ -1,16 +1,22 @@
var Class = require('../../../utils/Class');
var Event = require('../../../events/Event');
var MouseMoveEvent = function (nativeEvent)
{
Event.call(this, 'MOUSE_MOVE_EVENT');
var MouseMoveEvent = new Class({
this.data = nativeEvent;
Extends: Event,
this.x = nativeEvent.clientX;
this.y = nativeEvent.clientY;
};
initialize:
MouseMoveEvent.prototype = Object.create(Event.prototype);
MouseMoveEvent.prototype.constructor = MouseMoveEvent;
function MouseMoveEvent (nativeEvent)
{
Event.call(this, 'MOUSE_MOVE_EVENT');
this.data = nativeEvent;
this.x = nativeEvent.clientX;
this.y = nativeEvent.clientY;
}
});
module.exports = MouseMoveEvent;

View file

@ -1,16 +1,22 @@
var Class = require('../../../utils/Class');
var Event = require('../../../events/Event');
var MouseUpEvent = function (nativeEvent)
{
Event.call(this, 'MOUSE_UP_EVENT');
var MouseUpEvent = new Class({
this.data = nativeEvent;
Extends: Event,
this.x = nativeEvent.clientX;
this.y = nativeEvent.clientY;
};
initialize:
MouseUpEvent.prototype = Object.create(Event.prototype);
MouseUpEvent.prototype.constructor = MouseUpEvent;
function MouseUpEvent (nativeEvent)
{
Event.call(this, 'MOUSE_UP_EVENT');
this.data = nativeEvent;
this.x = nativeEvent.clientX;
this.y = nativeEvent.clientY;
}
});
module.exports = MouseUpEvent;

View file

@ -117,8 +117,6 @@ var Hermite = function (p1x, p1y, p2x, p2y, v1x, v1y, v2x, v2y, accuracy)
this.recalculate();
};
Hermite.prototype.constructor = Hermite;
Hermite.prototype = {
/**
@ -393,4 +391,6 @@ Object.defineProperties(Hermite.prototype, {
});
Hermite.prototype.constructor = Hermite;
module.exports = Hermite;

View file

@ -519,8 +519,6 @@ GlobalStateManager.prototype = {
// Sort the 'active' array based on the index property
this.active.sort(this.sortStates);
state.sys.updates.running = true;
if (state.create)
{
state.create.call(state, state.sys.settings.data);

View file

@ -10,7 +10,6 @@ var Settings = require('./Settings');
var StableSort = require('../utils/array/StableSort');
var StateManager = require('./systems/StateManager');
var TweenManager = require('../tween/TweenManager');
var UpdateManager = require('./systems/UpdateManager');
var Systems = function (state, config)
{
@ -45,7 +44,6 @@ var Systems = function (state, config)
this.stateManager;
this.time;
this.tweens;
this.updates;
// State properties
this.children;
@ -83,7 +81,6 @@ Systems.prototype = {
this.stateManager = new StateManager(this.state, game);
this.time = new Clock(this.state);
this.tweens = new TweenManager(this.state);
this.updates = new UpdateManager(this.state);
this.inject();
},