Skip to content

Commit 9053ca4

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents a137883 + 4f6790f commit 9053ca4

60 files changed

Lines changed: 1313 additions & 366 deletions

Some content is hidden

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

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ src/geom/polygon/Earcut.js
88
src/utils/array/StableSort.js
99
src/utils/object/Extend.js
1010
src/structs/RTree.js
11+
src/boot/ScaleManager.js

CHANGELOG.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,48 @@
11
# Change Log
22

3+
## Version 3.12.0 - Silica - in development
4+
5+
### New Features
6+
7+
* `Camera.resolution` is a new read-only property that holds the current game config resolution that the camera is using. This is used internally for viewport calculations.
8+
* `Text.resolution` and the method `Text.setResolution` allows you to control the resolution of a Static Text Game Object. By default it will be set to match the resolution set in the Game Config, but you can override it yourself via the TextStyle. It allows for much clearer text on High DPI devices, at the cost of larger internal Canvas textures for the Text - so please use with caution, as the more high res Text you have, the more memory it uses up. Fix #3528 (thanks @kirillbunin)
9+
* `TransformMatrix.getCSSMatrix` will return a CSS transform matrix formatted string from the current matrix values.
10+
* `CacheManager` now creates a new cache called `html` which is used to store all loaded HTML snippets.
11+
* `FileType.HTML` is a new file type loader that will load an HTML snippet and store it in the new `html` cache. Access it via `load.html` (this method was previously used to load html to textures, please see `load.htmlTexture` for this feature now)
12+
13+
### Updates
14+
15+
* `Camera.x` and `Camera.y` have been turned into getters / setters, mapped to the internal private values `_x` and `_y` respectively. This is so that setting the Camera viewport position directly will now update the new internal resolution calculation vars too.
16+
* `Camera.setScene` will now set the Cameras `resolution` property at the same time and update the internal viewport vars.
17+
* The `Cull Tiles` method used by the Dynamic Tilemap Layer has had a nice and significant optimization. It will now use the cull area dimensions to restrict the amount of tile iteration that takes place per layer, resulting in dramatic reductions in processing time on large layers, or multiple layers (thanks @tarsupin)
18+
* `GameObject.willRender` now takes a Camera as its only argument and uses it within the check. This has allowed me to remove 23 duplicate checks spread across the various Game Objects, all of which did the same thing, saving both KB and CPU time as the flags were being checked twice in most cases.
19+
* The file type loader `HTML` has been renamed to `HTMLTexture`. If you were using this then please change your calls from `load.html` to `load.htmlTexture`. The arguments remain the same.
20+
21+
### Game Config Resolution Specific Bug Fixes
22+
23+
Setting the `resolution` property in the Game Config to a value other than 1 would cause various errors in the API. The following have been fixed:
24+
25+
* The game canvas would be sized incorrectly, unless you had enabled auto resizing. It now scales the canvas to the size given, maintaining the resolution. Fix #3468 (thanks @Legomite)
26+
* Cameras with background colors set would display the filled color area at the wrong size. Camera fills now respect the resolution.
27+
* The Camera Fade Effect would display the fade fill rectangle at the wrong size. Camera fades now respect the resolution.
28+
* The Camera Flash Effect would display the fade fill rectangle at the wrong size. Camera flashes now respect the resolution.
29+
* The Camera Shake Effect would shake the Camera using the wrong width values. Camera Shakes now respect the resolution.
30+
* Input calculations would not factor in the Game Resolution correctly. If a Camera viewport was not at 0x0 or not the full size, or the Camera was rotated or zoomed, the input areas would be wrong if `resolution` was > 1. These are now factored in correctly and changing the resolution no longer breaks input. Fix #3606 (thanks @Secretmapper)
31+
32+
### Bug Fixes
33+
34+
* The `setCrop` method stored its crop object on the prototype chain by mistake, causing all Images or Sprites that were cropped to display the same frame. The crop data has been moved to the Game Object instance, where it should be, fixing this issue (thanks NoxBrutalis)
35+
* If an AudioFile failed to load and throw an incomplete error, it would cause the console.log to crash JavaScript when trying to log the error. It now only logs the message if it exists. Fix #3830 (thanks @kelostrada)
36+
37+
### Examples, Documentation and TypeScript
38+
39+
My thanks to the following for helping with the Phaser 3 Examples, Docs and TypeScript definitions, either by reporting errors, fixing them or helping author the docs:
40+
41+
@SBCGames
42+
43+
Thanks to @khaleb85 for fixing the super-annoying lag on the API Docs pages when it hung the browser while indexing the search field.
44+
45+
346
## Version 3.11.0 - Leafa - 13th July 2018
447

548
### Camera - New Features, Updates and Fixes

src/boot/Config.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ var ValueToColor = require('../display/color/ValueToColor');
5050
* @property {integer} [timeout=0] - [description]
5151
*/
5252

53+
/**
54+
* @typedef {object} DOMContainerConfig
55+
*
56+
* @property {boolean} [createContainer=false] - Create a div element in which DOM Elements will be contained. You must also provide a parent.
57+
* @property {boolean} [behindCanvas=false] - Place the DOM Container behind the Phaser Canvas. The default is to place it over the Canvas.
58+
*/
59+
5360
/**
5461
* @typedef {object} GameConfig
5562
*
@@ -83,6 +90,7 @@ var ValueToColor = require('../display/color/ValueToColor');
8390
* @property {boolean} [banner.hidePhaser=false] - [description]
8491
* @property {string} [banner.text='#ffffff'] - [description]
8592
* @property {string[]} [banner.background] - [description]
93+
* @property {DOMContainerConfig} [dom] - The DOM Container configuration object.
8694
* @property {FPSConfig} [fps] - [description]
8795
* @property {boolean} [render.antialias=true] - [description]
8896
* @property {boolean} [render.pixelArt=false] - [description]
@@ -212,6 +220,18 @@ var Config = new Class({
212220
*/
213221
this.autoFocus = GetValue(config, 'autoFocus', true);
214222

223+
// DOM Element Container
224+
225+
/**
226+
* @const {?boolean} Phaser.Boot.Config#domCreateContainer - [description]
227+
*/
228+
this.domCreateContainer = GetValue(config, 'dom.createContainer', false);
229+
230+
/**
231+
* @const {?boolean} Phaser.Boot.Config#domBehindCanvas - [description]
232+
*/
233+
this.domBehindCanvas = GetValue(config, 'dom.behindCanvas', false);
234+
215235
// Input
216236

217237
/**

src/boot/CreateDOMContainer.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2018 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
var AddToDOM = require('../dom/AddToDOM');
8+
9+
var CreateDOMContainer = function (game)
10+
{
11+
var config = game.config;
12+
13+
if (!config.parent || !config.domCreateContainer)
14+
{
15+
return;
16+
}
17+
18+
// DOM Element Container
19+
var div = document.createElement('div');
20+
21+
div.style = [
22+
'display: block;',
23+
'width: ' + game.canvas.width + 'px;',
24+
'height: ' + game.canvas.height + 'px;',
25+
'padding: 0; margin: 0;',
26+
'position: absolute;',
27+
'overflow: hidden;',
28+
'pointer-events: none;'
29+
].join(' ');
30+
31+
game.domContainer = div;
32+
33+
AddToDOM(div, config.parent);
34+
};
35+
36+
module.exports = CreateDOMContainer;

src/boot/CreateRenderer.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ var CreateRenderer = function (game)
6060
}
6161
else
6262
{
63-
game.canvas = CanvasPool.create(game, config.width, config.height, config.renderType);
63+
game.canvas = CanvasPool.create(game, config.width * config.resolution, config.height * config.resolution, config.renderType);
6464
}
6565

6666
// Does the game config provide some canvas css styles to use?
@@ -76,11 +76,8 @@ var CreateRenderer = function (game)
7676
}
7777

7878
// Zoomed?
79-
if (config.zoom !== 1)
80-
{
81-
game.canvas.style.width = (config.width * config.zoom).toString() + 'px';
82-
game.canvas.style.height = (config.height * config.zoom).toString() + 'px';
83-
}
79+
game.canvas.style.width = (config.width * config.zoom).toString() + 'px';
80+
game.canvas.style.height = (config.height * config.zoom).toString() + 'px';
8481

8582
if (config.renderType === CONST.HEADLESS)
8683
{

src/boot/Game.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var CacheManager = require('../cache/CacheManager');
1010
var CanvasPool = require('../display/canvas/CanvasPool');
1111
var Class = require('../utils/Class');
1212
var Config = require('./Config');
13+
var CreateDOMContainer = require('./CreateDOMContainer');
1314
var CreateRenderer = require('./CreateRenderer');
1415
var DataManager = require('../data/DataManager');
1516
var DebugHeader = require('./DebugHeader');
@@ -68,6 +69,20 @@ var Game = new Class({
6869
*/
6970
this.renderer = null;
7071

72+
/**
73+
* A reference to an HTML Div Element used as a DOM Element Container.
74+
*
75+
* Only set if `createDOMContainer` is `true` in the game config (by default it is `false`) and
76+
* if you provide a parent element to insert the Phaser Game inside.
77+
*
78+
* See the DOM Element Game Object for more details.
79+
*
80+
* @name Phaser.Game#domContainer
81+
* @type {HTMLDivElement}
82+
* @since 3.12.0
83+
*/
84+
this.domContainer = null;
85+
7186
/**
7287
* A reference to the HTML Canvas Element that Phaser uses to render the game.
7388
* This is created automatically by Phaser unless you provide a `canvas` property
@@ -305,6 +320,8 @@ var Game = new Class({
305320

306321
CreateRenderer(this);
307322

323+
CreateDOMContainer(this);
324+
308325
DebugHeader(this);
309326

310327
AddToDOM(this.canvas, this.config.parent);
@@ -611,6 +628,12 @@ var Game = new Class({
611628
this.config.width = width;
612629
this.config.height = height;
613630

631+
if (this.domContainer)
632+
{
633+
this.domContainer.style.width = width + 'px';
634+
this.domContainer.style.height = height + 'px';
635+
}
636+
614637
this.renderer.resize(width, height);
615638

616639
this.input.resize();
@@ -666,6 +689,11 @@ var Game = new Class({
666689
}
667690
}
668691

692+
if (this.domContainer)
693+
{
694+
this.domContainer.parentNode.removeChild(this.domContainer);
695+
}
696+
669697
this.loop.destroy();
670698

671699
this.pendingDestroy = false;

src/boot/ScaleManager.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2018 Photon Storm Ltd.
4+
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
5+
*/
6+
7+
var Class = require('../utils/Class');
8+
var GetValue = require('../utils/object/GetValue');
9+
10+
/*
11+
12+
scale: {
13+
width: 800,
14+
height: 600,
15+
resolution: window.devicePixelRatio,
16+
},
17+
18+
Canvas width / height in the element
19+
Canvas CSS width / height in the style
20+
21+
Detect orientation
22+
Lock orientation (Android only?)
23+
Full-screen support
24+
25+
Scale Mode -
26+
27+
28+
*/
29+
30+
/**
31+
* @classdesc
32+
* [description]
33+
*
34+
* @class ScaleManager
35+
* @memberOf Phaser.Boot
36+
* @constructor
37+
* @since 3.12.0
38+
*
39+
* @param {Phaser.Game} game - A reference to the Phaser.Game instance.
40+
* @param {ScaleManagerConfig} config
41+
*/
42+
var ScaleManager = new Class({
43+
44+
initialize:
45+
46+
function ScaleManager (game, config)
47+
{
48+
/**
49+
* A reference to the Phaser.Game instance.
50+
*
51+
* @name Phaser.Boot.ScaleManager#game
52+
* @type {Phaser.Game}
53+
* @readOnly
54+
* @since 3.12.0
55+
*/
56+
this.game = game;
57+
},
58+
59+
/**
60+
* Destroys the ScaleManager.
61+
*
62+
* @method Phaser.Boot.ScaleManager#destroy
63+
* @since 3.12.0
64+
*/
65+
destroy: function ()
66+
{
67+
this.game = null;
68+
}
69+
70+
});
71+
72+
module.exports = ScaleManager;

src/cache/CacheManager.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,15 @@ var CacheManager = new Class({
102102
*/
103103
this.text = new BaseCache();
104104

105+
/**
106+
* A Cache storing all html files, typically added via the Loader.
107+
*
108+
* @name Phaser.Cache.CacheManager#html
109+
* @type {Phaser.Cache.BaseCache}
110+
* @since 3.12.0
111+
*/
112+
this.html = new BaseCache();
113+
105114
/**
106115
* A Cache storing all WaveFront OBJ files, typically added via the Loader.
107116
*
@@ -181,6 +190,7 @@ var CacheManager = new Class({
181190
'shader',
182191
'audio',
183192
'text',
193+
'html',
184194
'obj',
185195
'tilemap',
186196
'xml'

0 commit comments

Comments
 (0)