Skip to content

Commit bc2263d

Browse files
committed
Fixed Camera3D Plugin, exposed it via camera3d in a Scene and added cameras to local array.
Closes phaserjs#3188
1 parent de4b308 commit bc2263d

5 files changed

Lines changed: 44 additions & 83 deletions

File tree

src/cameras/2d/CameraManager.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -182,36 +182,6 @@ var CameraManager = new Class({
182182
return null;
183183
},
184184

185-
/**
186-
* [description]
187-
*
188-
* @method Phaser.Cameras.Scene2D.CameraManager#addKeyControl
189-
* @since 3.0.0
190-
*
191-
* @param {[type]} config - [description]
192-
*
193-
* @return {[type]} [description]
194-
*/
195-
addKeyControl: function (config)
196-
{
197-
return new KeyControl(config);
198-
},
199-
200-
/**
201-
* [description]
202-
*
203-
* @method Phaser.Cameras.Scene2D.CameraManager#addSmoothedKeyControl
204-
* @since 3.0.0
205-
*
206-
* @param {[type]} config - [description]
207-
*
208-
* @return {[type]} [description]
209-
*/
210-
addSmoothedKeyControl: function (config)
211-
{
212-
return new SmoothedKeyControl(config);
213-
},
214-
215185
/*
216186
{
217187
cameras: [

src/cameras/sprite3d/CameraManager.js

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
var Class = require('../../utils/Class');
2-
var GetFastValue = require('../../utils/object/GetFastValue');
32
var OrthographicCamera = require('./OrthographicCamera');
43
var PerspectiveCamera = require('./PerspectiveCamera');
54
var PluginManager = require('../../plugins/PluginManager');
@@ -38,6 +37,14 @@ var CameraManager = new Class({
3837
*/
3938
this.systems = scene.sys;
4039

40+
/**
41+
* An Array of the Camera objects being managed by this Camera Manager.
42+
*
43+
* @property {Phaser.Cameras.Sprite3D.Camera[]} cameras
44+
* @since 3.0.0
45+
*/
46+
this.cameras = [];
47+
4148
if (!scene.sys.settings.isBooted)
4249
{
4350
scene.sys.events.once('boot', this.boot, this);
@@ -96,6 +103,8 @@ var CameraManager = new Class({
96103

97104
var camera = new OrthographicCamera(this.scene, width, height);
98105

106+
this.cameras.push(camera);
107+
99108
return camera;
100109
},
101110

@@ -121,18 +130,9 @@ var CameraManager = new Class({
121130

122131
var camera = new PerspectiveCamera(this.scene, fieldOfView, width, height);
123132

124-
return camera;
125-
},
133+
this.cameras.push(camera);
126134

127-
/**
128-
* [description]
129-
*
130-
* @method Phaser.Cameras.Sprite3D.CameraManager#destroy
131-
* @since 3.0.0
132-
*/
133-
destroy: function ()
134-
{
135-
this.scene = undefined;
135+
return camera;
136136
},
137137

138138
/**
@@ -170,58 +170,28 @@ var CameraManager = new Class({
170170
{
171171
var cameraIndex = this.cameras.indexOf(camera);
172172

173-
if (cameraIndex >= 0 && this.cameras.length > 1)
173+
if (cameraIndex !== -1)
174174
{
175-
this.cameraPool.push(this.cameras[cameraIndex]);
176175
this.cameras.splice(cameraIndex, 1);
177-
178-
if (this.main === camera)
179-
{
180-
this.main = this.cameras[0];
181-
}
182-
}
183-
},
184-
185-
/**
186-
* [description]
187-
*
188-
* @method Phaser.Cameras.Sprite3D.CameraManager#render
189-
* @since 3.0.0
190-
*
191-
* @param {[type]} renderer - [description]
192-
* @param {[type]} children - [description]
193-
* @param {[type]} interpolation - [description]
194-
*/
195-
render: function (renderer, children, interpolation)
196-
{
197-
var cameras = this.cameras;
198-
199-
for (var i = 0, l = cameras.length; i < l; ++i)
200-
{
201-
var camera = cameras[i];
202-
203-
camera.preRender();
204-
205-
renderer.render(this.scene, children, interpolation, camera);
206176
}
207177
},
208178

209179
/**
210180
* [description]
211181
*
212-
* @method Phaser.Cameras.Sprite3D.CameraManager#resetAll
182+
* @method Phaser.Cameras.Sprite3D.CameraManager#removeAll
213183
* @since 3.0.0
214184
*
215185
* @return {[type]} [description]
216186
*/
217-
resetAll: function ()
187+
removeAll: function ()
218188
{
219189
while (this.cameras.length > 0)
220190
{
221-
this.cameraPool.push(this.cameras.pop());
222-
}
191+
var camera = this.cameras.pop();
223192

224-
this.main = this.add();
193+
camera.destroy();
194+
}
225195

226196
return this.main;
227197
},
@@ -251,6 +221,17 @@ var CameraManager = new Class({
251221
*/
252222
shutdown: function ()
253223
{
224+
},
225+
226+
/**
227+
* [description]
228+
*
229+
* @method Phaser.Cameras.Sprite3D.CameraManager#destroy
230+
* @since 3.0.0
231+
*/
232+
destroy: function ()
233+
{
234+
this.scene = undefined;
254235
}
255236

256237
});

src/plugins/DefaultScenePlugins.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
var DefaultScenePlugins = [
99

10+
'CameraManager3D',
1011
'Clock',
1112
'DataManagerPlugin',
1213
'InputPlugin',

src/plugins/PluginManager.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ var PluginManager = new Class({
3131

3232
// console.log('PluginManager.global', pluginKey);
3333

34-
sys[pluginKey] = game[pluginKey];
35-
36-
// Scene level injection
37-
if (map.hasOwnProperty(pluginKey))
34+
if (game[pluginKey])
3835
{
39-
scene[map[pluginKey]] = sys[pluginKey];
36+
sys[pluginKey] = game[pluginKey];
37+
38+
// Scene level injection
39+
if (map.hasOwnProperty(pluginKey))
40+
{
41+
scene[map[pluginKey]] = sys[pluginKey];
42+
}
4043
}
4144
}
4245
},
@@ -51,6 +54,11 @@ var PluginManager = new Class({
5154
{
5255
var pluginKey = scenePlugins[i];
5356

57+
if (!plugins[pluginKey])
58+
{
59+
continue;
60+
}
61+
5462
var source = plugins[pluginKey];
5563

5664
// console.log('PluginManager.local', pluginKey, 'to', source.mapping);

src/scene/InjectionMap.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var InjectionMap = {
1414

1515
events: 'events',
1616
cameras: 'cameras',
17+
cameras3d: 'cameras3d',
1718
add: 'add',
1819
make: 'make',
1920
scenePlugin: 'scene',

0 commit comments

Comments
 (0)