Skip to content

Commit efbf276

Browse files
Merge remote-tracking branch 'origin/master'
2 parents 51aaa3e + 6687c0f commit efbf276

28 files changed

Lines changed: 337 additions & 260 deletions

v3/src/camera/2d/inc/GetWorldPoint.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
var Vector2 = require('../../../math/Vector2');
22

3-
var GetWorldPoint = function (screenPoint, output)
3+
var GetWorldPoint = function (x, y, output)
44
{
5+
if (output === undefined) { output = new Vector2(); }
6+
57
var cameraMatrix = this.matrix.matrix;
8+
69
var mva = cameraMatrix[0];
710
var mvb = cameraMatrix[1];
811
var mvc = cameraMatrix[2];
@@ -15,7 +18,10 @@ var GetWorldPoint = function (screenPoint, output)
1518

1619
if (!determinant)
1720
{
18-
return screenPoint;
21+
output.x = x;
22+
output.y = y;
23+
24+
return output;
1925
}
2026

2127
determinant = 1 / determinant;
@@ -26,22 +32,21 @@ var GetWorldPoint = function (screenPoint, output)
2632
var imd = mva * determinant;
2733
var ime = (mvc * mvf - mvd * mve) * determinant;
2834
var imf = (mvb * mve - mva * mvf) * determinant;
35+
2936
var c = Math.cos(this.rotation);
3037
var s = Math.sin(this.rotation);
38+
3139
var zoom = this.zoom;
40+
3241
var scrollX = this.scrollX;
3342
var scrollY = this.scrollY;
34-
var x = screenPoint.x + ((scrollX * c - scrollY * s) * zoom);
35-
var y = screenPoint.y + ((scrollX * s + scrollY * c) * zoom);
3643

37-
if (!output)
38-
{
39-
output = new Vector2();
40-
}
44+
var sx = x + ((scrollX * c - scrollY * s) * zoom);
45+
var sy = y + ((scrollX * s + scrollY * c) * zoom);
4146

4247
/* Apply transform to point */
43-
output.x = (x * ima + y * imc + ime);
44-
output.y = (x * imb + y * imd + imf);
48+
output.x = (sx * ima + sy * imc + ime);
49+
output.y = (sx * imb + sy * imd + imf);
4550

4651
return output;
4752
};

v3/src/camera/2d/inc/PreRender.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,25 @@ var PreRender = function ()
2121
{
2222
var bounds = this._bounds;
2323

24-
// width = bounds.width;
25-
// height = bounds.height;
26-
27-
// var boundsX = bounds.x;
28-
// var boundsY = bounds.y;
29-
// var boundsR = Math.max(bounds.right - width, width);
30-
// var boundsB = Math.max(bounds.bottom - height, height);
24+
var bw = Math.max(0, bounds.right - width);
25+
var bh = Math.max(0, bounds.bottom - height);
3126

3227
if (this.scrollX < bounds.x)
3328
{
3429
this.scrollX = bounds.x;
3530
}
36-
else if (this.scrollX > bounds.right)
31+
else if (this.scrollX > bw)
3732
{
38-
this.scrollX = bounds.right;
33+
this.scrollX = bw;
3934
}
4035

4136
if (this.scrollY < bounds.y)
4237
{
4338
this.scrollY = bounds.y;
4439
}
45-
else if (this.scrollY > bounds.bottom)
40+
else if (this.scrollY > bh)
4641
{
47-
this.scrollY = bounds.bottom;
42+
this.scrollY = bh;
4843
}
4944
}
5045

v3/src/camera/controls/KeyControl.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,22 @@ var KeyControl = new Class({
4646
start: function ()
4747
{
4848
this.active = (this.camera !== null);
49+
50+
return this;
4951
},
5052

5153
stop: function ()
5254
{
5355
this.active = false;
56+
57+
return this;
58+
},
59+
60+
setCamera: function (camera)
61+
{
62+
this.camera = camera;
63+
64+
return this;
5465
},
5566

5667
update: function (delta)

v3/src/camera/controls/SmoothedKeyControl.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,22 @@ var SmoothedKeyControl = new Class({
8181
start: function ()
8282
{
8383
this.active = (this.camera !== null);
84+
85+
return this;
8486
},
8587

8688
stop: function ()
8789
{
8890
this.active = false;
91+
92+
return this;
93+
},
94+
95+
setCamera: function (camera)
96+
{
97+
this.camera = camera;
98+
99+
return this;
89100
},
90101

91102
update: function (delta)

v3/src/camera/local/CameraManager.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ var CameraManager = new Class({
2828
this.main = this.cameras[0];
2929
},
3030

31-
add: require('./inc/Add2DCamera'),
3231
add3D: require('./inc/AddPerspectiveCamera'),
33-
addPerspectiveCamera: require('./inc/AddPerspectiveCamera'),
34-
addOrthographicCamera: require('./inc/AddOrthographicCamera'),
32+
add: require('./inc/Add2DCamera'),
3533
addExisting: require('./inc/AddExisting'),
3634
addKeyControl: require('./inc/AddKeyControl'),
35+
addOrthographicCamera: require('./inc/AddOrthographicCamera'),
36+
addPerspectiveCamera: require('./inc/AddPerspectiveCamera'),
3737
addSmoothedKeyControl: require('./inc/AddSmoothedKeyControl'),
3838
destroy: require('./inc/Destroy'),
3939
fromJSON: require('./inc/FromJSON'),
40+
getCamera: require('./inc/GetCamera'),
4041
getCameraBelowPointer: require('./inc/GetCameraBelowPointer'),
4142
remove: require('./inc/RemoveCamera'),
4243
render: require('./inc/Render'),

v3/src/camera/local/inc/Add2DCamera.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
var Camera = require('../../2d/Camera');
22

3-
var Add2DCamera = function (x, y, width, height, makeMain)
3+
var Add2DCamera = function (x, y, width, height, makeMain, name)
44
{
55
if (x === undefined) { x = 0; }
66
if (y === undefined) { y = 0; }
77
if (width === undefined) { width = this.scene.sys.game.config.width; }
88
if (height === undefined) { height = this.scene.sys.game.config.height; }
99
if (makeMain === undefined) { makeMain = false; }
10+
if (name === undefined) { name = ''; }
1011

1112
var camera = null;
1213

@@ -21,6 +22,7 @@ var Add2DCamera = function (x, y, width, height, makeMain)
2122
camera = new Camera(x, y, width, height);
2223
}
2324

25+
camera.setName(name);
2426
camera.setScene(this.scene);
2527

2628
this.cameras.push(camera);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var GetCamera = function (name)
2+
{
3+
this.cameras.forEach(function (camera)
4+
{
5+
if (camera.name === name)
6+
{
7+
return camera;
8+
}
9+
});
10+
11+
return null;
12+
};
13+
14+
module.exports = GetCamera;

v3/src/gameobjects/components/ScrollFactor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var ScrollFactor = {
22

3-
scrollFactorX: 1.0,
4-
scrollFactorY: 1.0,
3+
scrollFactorX: 1,
4+
scrollFactorY: 1,
55

66
setScrollFactor: function (x, y)
77
{

v3/src/gameobjects/components/TransformMatrix.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ var TransformMatrix = new Class({
118118
return this;
119119
},
120120

121+
121122
transformPoint: function (x, y, point)
122123
{
123124
if (point === undefined) { point = { x: 0, y: 0 }; }

v3/src/gameobjects/renderpass/RenderPass.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ var RenderPass = new Class({
176176
gl.bindTexture(gl.TEXTURE_2D, textureData.texture);
177177
gl.activeTexture(gl.TEXTURE0);
178178
}
179+
//renderer.spriteBatch.addRenderPassRect(x, y, width, height, this.scrollFactorX, this.scrollFactorY, camera, this.passShader, this.passRenderTarget);
179180
renderer.spriteBatch.flush(this.passShader, this.passRenderTarget);
180181
}
181182
},

0 commit comments

Comments
 (0)