var Class = require('../../../src/utils/Class'); var OrthographicCamera = require('./OrthographicCamera'); var PerspectiveCamera = require('./PerspectiveCamera'); var PluginCache = require('../../../src/plugins/PluginCache'); var CameraManager = new Class({ initialize: function CameraManager(scene){ this.scene = scene; this.systems = scene.sys; this.cameras = [] ; scene.sys.events.once('boot', this.boot, this); scene.sys.events.on('start', this.start, this); } , boot: function (){ this.systems.events.once('destroy', this.destroy, this); } , start: function (){ var eventEmitter = this.systems.events; eventEmitter.on('update', this.update, this); eventEmitter.once('shutdown', this.shutdown, this); } , add: function (fieldOfView, width, height){ return this.addPerspectiveCamera(fieldOfView, width, height); } , addOrthographicCamera: function (width, height){ var config = this.scene.sys.game.config; if (width === undefined) { width = config.width; } if (height === undefined) { height = config.height; } var camera = new OrthographicCamera(this.scene, width, height); this.cameras.push(camera); return camera; } , addPerspectiveCamera: function (fieldOfView, width, height){ var config = this.scene.sys.game.config; if (fieldOfView === undefined) { fieldOfView = 80; } if (width === undefined) { width = config.width; } if (height === undefined) { height = config.height; } var camera = new PerspectiveCamera(this.scene, fieldOfView, width, height); this.cameras.push(camera); return camera; } , getCamera: function (name){ for (var i = 0; i < (_AN_Read_length('length', this.cameras)); i++ ){ if (this.cameras[i].name === name) { return this.cameras[i]; } } return null ; } , removeCamera: function (camera){ var cameraIndex = this.cameras.indexOf(camera); if (cameraIndex !== -1) { this.cameras.splice(cameraIndex, 1); } } , removeAll: function (){ while ((_AN_Read_length('length', this.cameras)) > 0){ var camera = this.cameras.pop(); camera.destroy(); } return this.main; } , update: function (timestep, delta){ for (var i = 0, l = _AN_Read_length('length', this.cameras); i < l; ++i){ this.cameras[i].update(timestep, delta); } } , shutdown: function (){ var eventEmitter = this.systems.events; eventEmitter.off('update', this.update, this); eventEmitter.off('shutdown', this.shutdown, this); this.removeAll(); } , destroy: function (){ this.shutdown(); this.scene.sys.events.off('start', this.start, this); this.scene = null ; this.systems = null ; } } ); PluginCache.register('CameraManager3D', CameraManager, 'cameras3d'); module.exports = CameraManager;