Skip to content

Commit ebf4a50

Browse files
committed
Updated so Game Objects and States are using the new experimental Transform 2.
1 parent ff72fc5 commit ebf4a50

4 files changed

Lines changed: 39 additions & 23 deletions

File tree

v3/src/components/experimental-Transform-2.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ Transform.prototype.flattenTree = function (children, flatChildrenArray, childCo
8181
}
8282
return childCount;
8383
};
84-
Transform.prototype.addChild = function (transform)
84+
Transform.prototype.add = function (transform)
8585
{
8686
this.root.dirty = true;
8787
this.hasChildren = true;
8888
transform.root = this.root;
8989
this.children.push(transform);
9090
};
91-
Transform.prototype.removeChild = function (transform)
91+
Transform.prototype.remove = function (transform)
9292
{
9393
var children = this.children;
9494
var index = children.indexOf(transform);
@@ -160,7 +160,7 @@ Transform.prototype.update = function (parentTransformMatrix)
160160
};
161161
Transform.prototype.updateLocal = function ()
162162
{
163-
var local this.localMatrix.loadIdentity();
163+
var local = this.localMatrix.loadIdentity();
164164
local.translate(this.positionX, this.positionY);
165165
local.rotate(this.rotation);
166166
local.scale(this.scaleX, this.scaleY);
@@ -218,4 +218,6 @@ Object.defineProperties(Transform.prototype,{
218218
return Math.acos(a / Math.sqrt(a2 + c2)) * (Math.atan(-c / a) < 0 ? -1 : 1);
219219
}
220220
}
221-
});
221+
});
222+
223+
module.exports = Transform;

v3/src/components/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module.exports = {
22

3-
BaseTransform: require('./BaseTransform'),
3+
// BaseTransform: require('./BaseTransform'),
44
Children: require('./Children'),
55
Color: require('./Color'),
66
Data: require('./Data'),
7-
Transform: require('./Transform')
7+
Transform: require('./experimental-Transform-2')
88

99
};

v3/src/gameobjects/GameObject.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
55
*/
66

7-
var CONST = require('../const');
8-
var MATH_CONST = require('../math/const');
7+
// var CONST = require('../const');
8+
// var MATH_CONST = require('../math/const');
99
var ScaleModes = require('../renderer/ScaleModes');
1010
var Component = require('../components');
11-
var WrapAngle = require('../math/angle/Wrap');
11+
// var WrapAngle = require('../math/angle/Wrap');
1212

1313
/**
1414
* This is the base Game Object class that you can use when creating your own extended Game Objects.
@@ -39,7 +39,10 @@ var GameObject = function (state, x, y, texture, frame, parent)
3939
this.frame = frame;
4040

4141
// All GameObjects have the following components, always:
42-
this.transform = new Component.Transform(this, x, y);
42+
this.transform = new Component.Transform(this);
43+
44+
this.transform.positionX = x;
45+
this.transform.positionY = y;
4346

4447
// Optional? Maybe set on a per GO basis?
4548
this.data = new Component.Data(this);
@@ -108,13 +111,12 @@ Object.defineProperties(GameObject.prototype, {
108111

109112
get: function ()
110113
{
111-
return this.transform._posX;
114+
return this.transform.positionX;
112115
},
113116

114117
set: function (value)
115118
{
116-
this.transform._posX = value;
117-
this.transform.dirty = true;
119+
this.transform.positionX = value;
118120
}
119121

120122
},
@@ -125,17 +127,17 @@ Object.defineProperties(GameObject.prototype, {
125127

126128
get: function ()
127129
{
128-
return this.transform._posY;
130+
return this.transform.positionY;
129131
},
130132

131133
set: function (value)
132134
{
133-
this.transform._posY = value;
134-
this.transform.dirty = true;
135+
this.transform.positionY = value;
135136
}
136137

137138
},
138139

140+
/*
139141
scale: {
140142
141143
enumerable: true,
@@ -326,6 +328,7 @@ Object.defineProperties(GameObject.prototype, {
326328
}
327329
328330
},
331+
*/
329332

330333
// Color getters / setters
331334

v3/src/state/Systems.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var GameObjectCreator = require('./systems/GameObjectCreator');
1010
var Loader = require('./systems/Loader');
1111
var UpdateManager = require('./systems/UpdateManager');
1212
var Component = require('../components');
13-
var Camera = require('../camera/Camera');
13+
// var Camera = require('../camera/Camera');
1414
var Settings = require('./Settings');
1515
var RTree = require('../structs/RTree');
1616

@@ -38,13 +38,13 @@ var Systems = function (state, config)
3838
this.tree;
3939

4040
// State properties
41-
this.camera;
41+
// this.camera;
4242
this.children;
4343
this.color;
4444
this.data;
4545
this.fbo;
4646
this.time;
47-
// this.transform;
47+
this.transform;
4848
};
4949

5050
Systems.prototype.constructor = Systems;
@@ -73,11 +73,11 @@ Systems.prototype = {
7373

7474
// State specific properties (transform, data, children, etc)
7575

76-
this.camera = new Camera(this.state, 0, 0, this.settings.width, this.settings.height);
76+
// this.camera = new Camera(this.state, 0, 0, this.settings.width, this.settings.height);
7777
this.children = new Component.Children(this.state);
7878
this.color = new Component.Color(this.state);
7979
this.data = new Component.Data(this.state);
80-
// this.transform = this.camera.transform;
80+
this.transform = new Component.Transform(this.state);
8181

8282
this.inject();
8383
},
@@ -94,7 +94,7 @@ Systems.prototype = {
9494
this.state.data = this.data;
9595
this.state.settings = this.settings;
9696

97-
this.state.camera = this.camera;
97+
// this.state.camera = this.camera;
9898
// this.state.transform = this.camera.transform;
9999

100100
this.state.state = this.game.state;
@@ -123,8 +123,19 @@ Systems.prototype = {
123123
this.state.update(timestep, physicsStep);
124124
},
125125

126-
// Called just once per frame, regardless of speed
127126
render: function (interpolation, renderer)
127+
{
128+
this.transform.updateRoot();
129+
130+
// Now what? :)
131+
132+
// renderer.render(this.state, list, interpolation);
133+
134+
this.state.render(interpolation);
135+
},
136+
137+
// Called just once per frame, regardless of speed
138+
OLDrender: function (interpolation, renderer)
128139
{
129140
this.updates.start();
130141

0 commit comments

Comments
 (0)