var BuildGameObject = require('../../../src/gameobjects/BuildGameObject'); var BuildGameObjectAnimation = require('../../../src/gameobjects/BuildGameObjectAnimation'); var Class = require('../../../src/utils/Class'); var GetAdvancedValue = require('../../../src/utils/object/GetAdvancedValue'); var OrthographicCamera = require('./OrthographicCamera'); var PerspectiveCamera = require('./PerspectiveCamera'); var ScenePlugin = require('../../../src/plugins/ScenePlugin'); var Sprite3D = require('./sprite3d/Sprite3D'); var Camera3DPlugin = new Class({ Extends: ScenePlugin, initialize: function Camera3DPlugin(scene, pluginManager){ ScenePlugin.call(this, scene, pluginManager); this.cameras = [] ; pluginManager.registerGameObject('sprite3D', this.sprite3DFactory, this.sprite3DCreator); } , sprite3DFactory: function (x, y, z, key, frame){ var sprite = new Sprite3D(this.scene, x, y, z, key, frame); this.displayList.add(sprite.gameObject); this.updateList.add(sprite.gameObject); return sprite; } , sprite3DCreator: function (config, addToScene){ if (config === undefined) { config = { } ; } var key = GetAdvancedValue(config, 'key', null ); var frame = GetAdvancedValue(config, 'frame', null ); var sprite = new Sprite3D(this.scene, 0, 0, key, frame); if (addToScene !== undefined) { config.add = addToScene; } BuildGameObject(this.scene, sprite, config); BuildGameObjectAnimation(sprite, config); return sprite; } , 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.pluginManager = null ; this.game = null ; this.scene = null ; this.systems = null ; } } ); module.exports = Camera3DPlugin;