Skip to content

Commit 26956d3

Browse files
Merge remote-tracking branch 'origin/master'
2 parents f692aad + a3b8a25 commit 26956d3

59 files changed

Lines changed: 1770 additions & 389 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

v3/src/camera/2d/Camera.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ var Camera = new Class({
6565
this._id = 0;
6666
},
6767

68-
cameraToWorld: require('./inc/CameraToWorld'),
6968
centerToBounds: require('./inc/CenterToBounds'),
7069
centerToSize: require('./inc/CenterToSize'),
7170
cull: require('./inc/Cull'),
@@ -74,6 +73,7 @@ var Camera = new Class({
7473
destroy: require('./inc/Destroy'),
7574
fade: require('./inc/Fade'),
7675
flash: require('./inc/Flash'),
76+
getWorldPoint: require('./inc/GetWorldPoint'),
7777
ignore: require('./inc/Ignore'),
7878
preRender: require('./inc/PreRender'),
7979
removeBounds: require('./inc/RemoveBounds'),
@@ -93,8 +93,7 @@ var Camera = new Class({
9393
startFollow: require('./inc/StartFollow'),
9494
stopFollow: require('./inc/StopFollow'),
9595
toJSON: require('./inc/ToJSON'),
96-
update: require('./inc/Update'),
97-
worldToCamera: require('./inc/WorldToCamera')
96+
update: require('./inc/Update')
9897

9998
});
10099

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
var CameraToWorld = function (pointIn, pointOut)
1+
var Vector2 = require('../../../math/Vector2');
2+
3+
var GetWorldPoint = function (screenPoint, output)
24
{
35
var cameraMatrix = this.matrix.matrix;
46
var mva = cameraMatrix[0];
@@ -13,7 +15,7 @@ var CameraToWorld = function (pointIn, pointOut)
1315

1416
if (!determinant)
1517
{
16-
return pointIn;
18+
return screenPoint;
1719
}
1820

1921
determinant = 1 / determinant;
@@ -29,19 +31,19 @@ var CameraToWorld = function (pointIn, pointOut)
2931
var zoom = this.zoom;
3032
var scrollX = this.scrollX;
3133
var scrollY = this.scrollY;
32-
var x = pointIn.x + ((scrollX * c - scrollY * s) * zoom);
33-
var y = pointIn.y + ((scrollX * s + scrollY * c) * zoom);
34+
var x = screenPoint.x + ((scrollX * c - scrollY * s) * zoom);
35+
var y = screenPoint.y + ((scrollX * s + scrollY * c) * zoom);
3436

35-
if (!pointOut)
37+
if (!output)
3638
{
37-
pointOut = { x: 0, y: 0 };
39+
output = new Vector2();
3840
}
3941

4042
/* Apply transform to point */
41-
pointOut.x = (x * ima + y * imc + ime);
42-
pointOut.y = (x * imb + y * imd + imf);
43+
output.x = (x * ima + y * imc + ime);
44+
output.y = (x * imb + y * imd + imf);
4345

44-
return pointOut;
46+
return output;
4547
};
4648

47-
module.exports = CameraToWorld;
49+
module.exports = GetWorldPoint;

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

Lines changed: 0 additions & 65 deletions
This file was deleted.

v3/src/gameobjects/GameObject.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ var GameObject = new Class({
244244
*/
245245
destroy: function ()
246246
{
247+
if (this.preDestroy)
248+
{
249+
this.preDestroy();
250+
}
251+
247252
this.scene.sys.displayList.remove(this);
248253
this.scene.sys.updateList.remove(this);
249254

v3/src/gameobjects/text/TextStyle.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ var TextStyle = new Class({
9090

9191
syncFont: function (canvas, context)
9292
{
93-
if (this.rtl)
94-
{
95-
canvas.dir = 'rtl';
96-
}
97-
9893
context.font = this.font;
9994
context.textBaseline = 'alphabetic';
10095

v3/src/gameobjects/text/static/Text.js

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
1+
var AddToDOM = require('../../../dom/AddToDOM');
2+
var CanvasPool = require('../../../display/canvas/CanvasPool');
23
var Class = require('../../../utils/Class');
3-
var GameObject = require('../../GameObject');
44
var Components = require('../../components');
5-
var CanvasPool = require('../../../display/canvas/CanvasPool');
5+
var GameObject = require('../../GameObject');
6+
var GetTextSize = require('../GetTextSize');
7+
var RemoveFromDOM = require('../../../dom/RemoveFromDOM');
68
var TextRender = require('./TextRender');
79
var TextStyle = require('../TextStyle');
8-
var GetTextSize = require('../GetTextSize');
910

1011
var Text = new Class({
1112

@@ -32,10 +33,6 @@ var Text = new Class({
3233
{
3334
if (x === undefined) { x = 0; }
3435
if (y === undefined) { y = 0; }
35-
if (text === undefined) { text = ''; }
36-
37-
// Cast to string whatever our value may be (numeric, etc)
38-
text = text.toString();
3936

4037
GameObject.call(this, scene, 'Text');
4138

@@ -64,7 +61,8 @@ var Text = new Class({
6461
*/
6562
this.splitRegExp = /(?:\r\n|\r|\n)/;
6663

67-
this.text = (Array.isArray(text)) ? text.join('\n') : text;
64+
// This is populated in this.setText
65+
this.text = '';
6866

6967
this.resolution = 1;
7068

@@ -81,10 +79,9 @@ var Text = new Class({
8179
this.canvasTexture = null;
8280
this.dirty = false;
8381

84-
if (text !== '')
85-
{
86-
this.updateText();
87-
}
82+
this.initRTL();
83+
84+
this.setText(text);
8885

8986
var _this = this;
9087

@@ -95,6 +92,32 @@ var Text = new Class({
9592
});
9693
},
9794

95+
initRTL: function ()
96+
{
97+
if (!this.style.rtl)
98+
{
99+
return;
100+
}
101+
102+
// Here is where the crazy starts.
103+
//
104+
// Due to browser implementation issues, you cannot fillText BiDi text to a canvas
105+
// that is not part of the DOM. It just completely ignores the direction property.
106+
107+
this.canvas.dir = 'rtl';
108+
109+
// Experimental atm, but one day ...
110+
this.context.direction = 'rtl';
111+
112+
// Add it to the DOM, but hidden within the parent canvas.
113+
this.canvas.style.display = 'none';
114+
115+
AddToDOM(this.canvas, this.scene.sys.canvas);
116+
117+
// And finally we set the x origin
118+
this.originX = 1;
119+
},
120+
98121
setText: function (value)
99122
{
100123
if (Array.isArray(value))
@@ -255,13 +278,20 @@ var Text = new Class({
255278
linePositionY += (textSize.lineSpacing * i);
256279
}
257280

258-
if (style.align === 'right')
281+
if (style.rtl)
259282
{
260-
linePositionX += textSize.width - textSize.lineWidths[i];
283+
linePositionX = w - linePositionX;
261284
}
262-
else if (style.align === 'center')
285+
else
263286
{
264-
linePositionX += (textSize.width - textSize.lineWidths[i]) / 2;
287+
if (style.align === 'right')
288+
{
289+
linePositionX += textSize.width - textSize.lineWidths[i];
290+
}
291+
else if (style.align === 'center')
292+
{
293+
linePositionX += (textSize.width - textSize.lineWidths[i]) / 2;
294+
}
265295
}
266296

267297
if (this.autoRound)
@@ -315,7 +345,18 @@ var Text = new Class({
315345
out.data = data;
316346

317347
return out;
348+
},
349+
350+
preDestroy: function ()
351+
{
352+
if (this.style.rtl)
353+
{
354+
RemoveFromDOM(this.canvas);
355+
}
356+
357+
CanvasPool.remove(this.canvas);
318358
}
359+
319360
});
320361

321362
module.exports = Text;

v3/src/gameobjects/tilemap/ImageCollection.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Note: direct port from v2
2+
13
/**
24
* An Image Collection is a special tileset containing mulitple images, with no slicing into each image.
35
*

v3/src/gameobjects/tilemap/ParseToTilemap.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ var Tilemap = require('./Tilemap');
1111
*
1212
* @param {Scene} scene - [description]
1313
* @param {string} [key] - The key in the Phaser cache that corresponds to the loaded tilemap data.
14-
* @param {number} [tileWidth=32] - The width of a tile in pixels.
15-
* @param {number} [tileHeight=32] - The height of a tile in pixels.
16-
* @param {number} [width=10] - The width of the map in tiles.
17-
* @param {number} [height=10] - The height of the map in tiles.
18-
* @param {array} [data] - Instead of loading from the cache, you can also load directly from a 2D
19-
* array of tile indexes.
14+
* @param {integer} [tileWidth=32] - The width of a tile in pixels.
15+
* @param {integer} [tileHeight=32] - The height of a tile in pixels.
16+
* @param {integer} [width=10] - The width of the map in tiles.
17+
* @param {integer} [height=10] - The height of the map in tiles.
18+
* @param {integer[][]} [data] - Instead of loading from the cache, you can also load directly from
19+
* a 2D array of tile indexes.
2020
* @param {boolean} [insertNull=false] - Controls how empty tiles, tiles with an index of -1, in the
2121
* map data are handled. If `true`, empty locations will get a value of `null`. If `false`, empty
2222
* location will get a Tile object with an index of -1. If you've a large sparsely populated map and

0 commit comments

Comments
 (0)