Skip to content

Commit 48f90fe

Browse files
committed
Implemented a State based MainLoop system, with fully split logic / render cycles and frame rate. Each State can now set its own frame rate. Added in more Camera commands, moved the Tween Manager into the State Systems, and started work on the new heavily reduced Game object.
1 parent b3c2ddb commit 48f90fe

21 files changed

Lines changed: 1774 additions & 1303 deletions

build/phaser3-config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
<script src="$path/src/states/StateManager.js"></script>
6868
<script src="$path/src/states/StateSettings.js"></script>
6969
<script src="$path/src/states/StateSystems.js"></script>
70+
<script src="$path/src/states/MainLoop.js"></script>
7071
7172
<script src="$path/src/core/Signal.js"></script>
7273
<script src="$path/src/core/SignalBinding.js"></script>

src/camera/Camera.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
* @param {number} width - The width of the view rectangle
1818
* @param {number} height - The height of the view rectangle
1919
*/
20-
Phaser.Camera = function (state, x, y, width, height)
20+
Phaser.Camera = function (state, x, y, viewportWidth, viewportHeight)
2121
{
22-
console.log('Camera');
23-
2422
/**
2523
* The State that this Camera belongs to. A Camera can only belong to one State, and a State only
2624
* has one Camera.
@@ -33,9 +31,9 @@ Phaser.Camera = function (state, x, y, width, height)
3331
*/
3432
this.game = state.game;
3533

36-
this.width = width;
34+
this.viewportWidth = viewportWidth;
3735

38-
this.height = height;
36+
this.viewportHeight = viewportHeight;
3937

4038
this.transform = new Phaser.Component.Transform(this, x, y);
4139

@@ -78,9 +76,9 @@ Phaser.Camera.prototype = {
7876
// var vh = this.view.bottom + this._shake.y;
7977

8078
var vx = this.x;
81-
var vw = this.x + this.width;
79+
var vw = this.x + this.viewportWidth;
8280
var vy = this.y;
83-
var vh = this.y + this.height;
81+
var vh = this.y + this.viewportHeight;
8482

8583
// Make sure we didn't go outside the cameras bounds
8684
if (vx <= this.bounds.x * this.scale.x)
@@ -131,8 +129,7 @@ Phaser.Camera.prototype = {
131129
}
132130
}
133131

134-
},
135-
132+
}
136133

137134
};
138135

@@ -180,7 +177,7 @@ Object.defineProperties(Phaser.Camera.prototype, {
180177

181178
get: function ()
182179
{
183-
return this.transform._posX + (this.width * this.transform._scaleX);
180+
return this.transform._posX + (this.viewportWidth * this.transform._scaleX);
184181
}
185182

186183
},
@@ -191,7 +188,7 @@ Object.defineProperties(Phaser.Camera.prototype, {
191188

192189
get: function ()
193190
{
194-
return this.transform._posY + (this.height * this.transform._scaleY);
191+
return this.transform._posY + (this.viewportHeight * this.transform._scaleY);
195192
}
196193

197194
},

src/components/Transform.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ Phaser.Component.Transform = function (gameObject, x, y, scaleX, scaleY)
1616
if (scaleX === undefined) { scaleX = 1; }
1717
if (scaleY === undefined) { scaleY = 1; }
1818

19-
this.game = gameObject.game;
20-
2119
this.gameObject = gameObject;
2220

21+
this.state = gameObject.state;
22+
23+
this.game = gameObject.state.game;
24+
2325
// Local Transform
2426
// a = scale X
2527
// b = shear Y
@@ -56,12 +58,12 @@ Phaser.Component.Transform = function (gameObject, x, y, scaleX, scaleY)
5658

5759
this._dirty = true;
5860

59-
this.game.updates.add(this);
61+
this.state.sys.updates.add(this);
6062

6163
// The parent Transform (NOT the parent GameObject, although very often they are related)
6264
this.parent = null;
6365

64-
// Any child Tranforms of this one - note that they don't have to belong to Game Objects
66+
// Any child Transforms of this one - note that they don't have to belong to Game Objects
6567
// that are children of the owner of this Transform
6668
this.children = [];
6769
};
@@ -515,6 +517,11 @@ Phaser.Component.Transform.prototype = {
515517

516518
},
517519

520+
getVertexData: function (interpolationPercentage)
521+
{
522+
return this.glVertextData;
523+
},
524+
518525
cloneVertexData: function ()
519526
{
520527
var src = this.glVertextData;
@@ -778,7 +785,7 @@ Object.defineProperties(Phaser.Component.Transform.prototype, {
778785
{
779786
if (!this._dirty)
780787
{
781-
this.game.updates.add(this);
788+
this.state.sys.updates.add(this);
782789
}
783790

784791
this._dirty = true;

src/components/UpdateManager.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
*
1010
* @class
1111
*/
12-
Phaser.UpdateManager = function (game)
12+
Phaser.UpdateManager = function (state)
1313
{
14-
this.game = game;
14+
this.state = state;
15+
16+
this.game = state.game;
1517

1618
this.list = [];
1719

0 commit comments

Comments
 (0)