Skip to content

Commit b6bef1d

Browse files
committed
Fixed issue with component private vars being shared.
Added Key Capture to Keyboard Manager. Added rotation and angle wrapping. Optmized getBounds.
1 parent 2d10cff commit b6bef1d

9 files changed

Lines changed: 134 additions & 80 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: 'ee28bed0-f9ea-11e6-8c46-dd1a5325b6e9'
2+
build: 'a913e160-fa32-11e6-a501-2b18fd50adf3'
33
};
44
module.exports = CHECKSUM;

v3/src/components/Alpha.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@ var Clamp = require('../math/Clamp');
22

33
// Alpha Component
44

5-
var _alpha = 1;
6-
75
// bitmask flag for GameObject.renderMask
86
var _FLAG = 2; // 0010
97

108
var Alpha = {
119

10+
_alpha: 1,
11+
1212
alpha: {
1313

1414
get: function ()
1515
{
16-
return _alpha;
16+
return this._alpha;
1717
},
1818

1919
set: function (value)
2020
{
21-
_alpha = Clamp(value, 0, 1);
21+
this._alpha = Clamp(value, 0, 1);
2222

23-
if (_alpha === 0)
23+
if (this._alpha === 0)
2424
{
2525
this.renderFlags &= ~_FLAG;
2626
}

v3/src/components/BlendMode.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ var BlendModes = require('../renderer/BlendModes');
22

33
// BlendMode Component
44

5-
var _blendMode = BlendModes.NORMAL;
6-
75
var BlendMode = {
86

7+
_blendMode: BlendModes.NORMAL,
8+
99
blendMode: {
1010

1111
get: function ()
1212
{
13-
return _blendMode;
13+
return this._blendMode;
1414
},
1515

1616
set: function (value)
@@ -19,7 +19,7 @@ var BlendMode = {
1919

2020
if (value >= 0 && value <= 16)
2121
{
22-
_blendMode = value;
22+
this._blendMode = value;
2323
}
2424
}
2525

v3/src/components/GetBounds.js

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,62 @@ var GetBounds = {
22

33
getBounds: function ()
44
{
5-
var a = this.angle;
65
var r = this.rotation;
76

8-
var hct = this.height * Math.cos(r);
97
var wct = this.width * Math.cos(r);
10-
var hst = this.height * Math.sin(r);
8+
var hct = this.height * Math.cos(r);
9+
1110
var wst = this.width * Math.sin(r);
11+
var hst = this.height * Math.sin(r);
1212

1313
var x = this.x;
1414
var y = this.y;
1515

16-
var x_min;
17-
var x_max;
18-
var y_min;
19-
var y_max;
16+
var xMin = x;
17+
var xMax = x;
18+
var yMin = y;
19+
var yMax = y;
2020

21-
if (a > 0)
21+
if (r > 0)
2222
{
23-
if (a < 90)
23+
if (r < 1.5707963267948966)
2424
{
2525
// 0 < theta < 90
26-
y_min = y;
27-
y_max = y + hct + wst;
28-
x_min = x - hst;
29-
x_max = x + wct;
26+
yMax = y + hct + wst;
27+
xMin = x - hst;
28+
xMax = x + wct;
3029
}
3130
else
3231
{
3332
// 90 <= theta <= 180
34-
y_min = y + hct;
35-
y_max = y + wst;
36-
x_min = x - hst + wct;
37-
x_max = x;
33+
yMin = y + hct;
34+
yMax = y + wst;
35+
xMin = x - hst + wct;
3836
}
3937
}
4038
else
4139
{
42-
if (a > -90)
40+
if (r > -1.5707963267948966)
4341
{
4442
// -90 < theta <= 0
45-
y_min = y + wst;
46-
y_max = y + hct;
47-
x_min = x;
48-
x_max = x + wct - hst;
43+
yMin = y + wst;
44+
yMax = y + hct;
45+
xMax = x + wct - hst;
4946
}
5047
else
5148
{
5249
// -180 <= theta <= -90
53-
y_min = y + wst + hct;
54-
y_max = y;
55-
x_min = x + wct;
56-
x_max = x - hst;
50+
yMin = y + wst + hct;
51+
xMin = x + wct;
52+
xMax = x - hst;
5753
}
5854
}
5955

6056
return {
61-
x: x_min,
62-
y: y_min,
63-
width: x_max - x_min,
64-
height: y_max - y_min
57+
x: xMin,
58+
y: yMin,
59+
width: xMax - xMin,
60+
height: yMax - yMin
6561
};
6662
}
6763
};

v3/src/components/ScaleMode.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ var ScaleModes = require('../renderer/ScaleModes');
22

33
// ScaleMode Component
44

5-
var _scaleMode = ScaleModes.DEFAULT;
6-
75
var ScaleMode = {
86

7+
_scaleMode: ScaleModes.DEFAULT,
8+
99
scaleMode: {
1010

1111
get: function ()
1212
{
13-
return _scaleMode;
13+
return this._scaleMode;
1414
},
1515

1616
set: function (value)
1717
{
1818
if (value === ScaleModes.LINEAR || value === ScaleModes.NEAREST)
1919
{
20-
_scaleMode = value;
20+
this._scaleMode = value;
2121
}
2222
}
2323

v3/src/components/Transform.js

Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
var MATH_CONST = require('../math/const');
2-
var WrapAngle = require('../math/angle/WrapDegrees');
2+
var WrapAngle = require('../math/angle/Wrap');
3+
var WrapAngleDegrees = require('../math/angle/WrapDegrees');
34

4-
var _scaleX = 1;
5-
var _scaleY = 1;
6-
7-
// bitmask flag for GameObject.renderMask (used by Scale)
5+
// global bitmask flag for GameObject.renderMask (used by Scale)
86
var _FLAG = 4; // 0100
97

108
// Transform Component
119

1210
var Transform = {
1311

12+
// "private" properties
13+
_scaleX: 1,
14+
_scaleY: 1,
15+
_rotation: 0,
16+
1417
x: 0,
1518
y: 0,
1619
z: 0,
1720

18-
rotation: 0,
19-
2021
anchorX: 0,
2122
anchorY: 0,
2223

@@ -27,14 +28,14 @@ var Transform = {
2728

2829
get: function ()
2930
{
30-
return _scaleX;
31+
return this._scaleX;
3132
},
3233

3334
set: function (value)
3435
{
35-
_scaleX = value;
36+
this._scaleX = value;
3637

37-
if (_scaleX === 0)
38+
if (this._scaleX === 0)
3839
{
3940
this.renderFlags &= ~_FLAG;
4041
}
@@ -50,14 +51,14 @@ var Transform = {
5051

5152
get: function ()
5253
{
53-
return _scaleY;
54+
return this._scaleY;
5455
},
5556

5657
set: function (value)
5758
{
58-
_scaleY = value;
59+
this._scaleY = value;
5960

60-
if (_scaleY === 0)
61+
if (this._scaleY === 0)
6162
{
6263
this.renderFlags &= ~_FLAG;
6364
}
@@ -69,6 +70,34 @@ var Transform = {
6970

7071
},
7172

73+
angle: {
74+
75+
get: function ()
76+
{
77+
return WrapAngleDegrees(this._rotation * MATH_CONST.RAD_TO_DEG);
78+
},
79+
80+
set: function (value)
81+
{
82+
// value is in degrees
83+
this.rotation = WrapAngleDegrees(value) * MATH_CONST.DEG_TO_RAD;
84+
}
85+
},
86+
87+
rotation: {
88+
89+
get: function ()
90+
{
91+
return this._rotation;
92+
},
93+
94+
set: function (value)
95+
{
96+
// value is in radians
97+
this._rotation = WrapAngle(value);
98+
}
99+
},
100+
72101
setPosition: function (x, y)
73102
{
74103
if (y === undefined) { y = x; }
@@ -79,6 +108,13 @@ var Transform = {
79108
return this;
80109
},
81110

111+
setRotation: function (radians)
112+
{
113+
this.rotation = radians;
114+
115+
return this;
116+
},
117+
82118
setScale: function (x, y)
83119
{
84120
if (x === undefined) { x = 1; }
@@ -110,20 +146,6 @@ var Transform = {
110146
this.offsetY = y;
111147

112148
return this;
113-
},
114-
115-
angle: {
116-
117-
get: function ()
118-
{
119-
return WrapAngle(this.rotation * MATH_CONST.RAD_TO_DEG);
120-
},
121-
122-
set: function (value)
123-
{
124-
// value is in degrees
125-
this.rotation = WrapAngle(value) * MATH_CONST.DEG_TO_RAD;
126-
}
127149
}
128150

129151
};

v3/src/components/Visible.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11

22
// Visible Component
33

4-
var _visible = true;
5-
64
// bitmask flag for GameObject.renderMask
75
var _FLAG = 1; // 0001
86

97
var Visible = {
108

9+
_visible: true,
10+
1111
visible: {
1212

1313
get: function ()
1414
{
15-
return _visible;
15+
return this._visible;
1616
},
1717

1818
set: function (value)
1919
{
2020
if (value)
2121
{
22-
_visible = true;
22+
this._visible = true;
2323
this.renderFlags |= _FLAG;
2424
}
2525
else
2626
{
27-
_visible = false;
27+
this._visible = false;
2828
this.renderFlags &= ~_FLAG;
2929
}
3030
}

v3/src/gameobjects/image/Image.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ var Image = new Class({
2424
{
2525
GameObject.call(this, state);
2626

27-
this.setPosition(x, y);
2827
this.setTexture(texture, frame);
28+
this.setPosition(x, y);
2929
}
3030

3131
});

0 commit comments

Comments
 (0)