Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Edwin222 2018-07-21 17:26:29 +09:00
commit 9053ca456b
60 changed files with 1313 additions and 366 deletions

View file

@ -8,3 +8,4 @@ src/geom/polygon/Earcut.js
src/utils/array/StableSort.js
src/utils/object/Extend.js
src/structs/RTree.js
src/boot/ScaleManager.js

View file

@ -1,5 +1,48 @@
# Change Log
## Version 3.12.0 - Silica - in development
### New Features
* `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.
* `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)
* `TransformMatrix.getCSSMatrix` will return a CSS transform matrix formatted string from the current matrix values.
* `CacheManager` now creates a new cache called `html` which is used to store all loaded HTML snippets.
* `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)
### Updates
* `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.
* `Camera.setScene` will now set the Cameras `resolution` property at the same time and update the internal viewport vars.
* 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)
* `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.
* 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.
### Game Config Resolution Specific Bug Fixes
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:
* 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)
* Cameras with background colors set would display the filled color area at the wrong size. Camera fills now respect the resolution.
* The Camera Fade Effect would display the fade fill rectangle at the wrong size. Camera fades now respect the resolution.
* The Camera Flash Effect would display the fade fill rectangle at the wrong size. Camera flashes now respect the resolution.
* The Camera Shake Effect would shake the Camera using the wrong width values. Camera Shakes now respect the resolution.
* 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)
### Bug Fixes
* 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)
* 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)
### Examples, Documentation and TypeScript
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:
@SBCGames
Thanks to @khaleb85 for fixing the super-annoying lag on the API Docs pages when it hung the browser while indexing the search field.
## Version 3.11.0 - Leafa - 13th July 2018
### Camera - New Features, Updates and Fixes

View file

@ -50,6 +50,13 @@ var ValueToColor = require('../display/color/ValueToColor');
* @property {integer} [timeout=0] - [description]
*/
/**
* @typedef {object} DOMContainerConfig
*
* @property {boolean} [createContainer=false] - Create a div element in which DOM Elements will be contained. You must also provide a parent.
* @property {boolean} [behindCanvas=false] - Place the DOM Container behind the Phaser Canvas. The default is to place it over the Canvas.
*/
/**
* @typedef {object} GameConfig
*
@ -83,6 +90,7 @@ var ValueToColor = require('../display/color/ValueToColor');
* @property {boolean} [banner.hidePhaser=false] - [description]
* @property {string} [banner.text='#ffffff'] - [description]
* @property {string[]} [banner.background] - [description]
* @property {DOMContainerConfig} [dom] - The DOM Container configuration object.
* @property {FPSConfig} [fps] - [description]
* @property {boolean} [render.antialias=true] - [description]
* @property {boolean} [render.pixelArt=false] - [description]
@ -212,6 +220,18 @@ var Config = new Class({
*/
this.autoFocus = GetValue(config, 'autoFocus', true);
// DOM Element Container
/**
* @const {?boolean} Phaser.Boot.Config#domCreateContainer - [description]
*/
this.domCreateContainer = GetValue(config, 'dom.createContainer', false);
/**
* @const {?boolean} Phaser.Boot.Config#domBehindCanvas - [description]
*/
this.domBehindCanvas = GetValue(config, 'dom.behindCanvas', false);
// Input
/**

View file

@ -0,0 +1,36 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var AddToDOM = require('../dom/AddToDOM');
var CreateDOMContainer = function (game)
{
var config = game.config;
if (!config.parent || !config.domCreateContainer)
{
return;
}
// DOM Element Container
var div = document.createElement('div');
div.style = [
'display: block;',
'width: ' + game.canvas.width + 'px;',
'height: ' + game.canvas.height + 'px;',
'padding: 0; margin: 0;',
'position: absolute;',
'overflow: hidden;',
'pointer-events: none;'
].join(' ');
game.domContainer = div;
AddToDOM(div, config.parent);
};
module.exports = CreateDOMContainer;

View file

@ -60,7 +60,7 @@ var CreateRenderer = function (game)
}
else
{
game.canvas = CanvasPool.create(game, config.width, config.height, config.renderType);
game.canvas = CanvasPool.create(game, config.width * config.resolution, config.height * config.resolution, config.renderType);
}
// Does the game config provide some canvas css styles to use?
@ -76,11 +76,8 @@ var CreateRenderer = function (game)
}
// Zoomed?
if (config.zoom !== 1)
{
game.canvas.style.width = (config.width * config.zoom).toString() + 'px';
game.canvas.style.height = (config.height * config.zoom).toString() + 'px';
}
game.canvas.style.width = (config.width * config.zoom).toString() + 'px';
game.canvas.style.height = (config.height * config.zoom).toString() + 'px';
if (config.renderType === CONST.HEADLESS)
{

View file

@ -10,6 +10,7 @@ var CacheManager = require('../cache/CacheManager');
var CanvasPool = require('../display/canvas/CanvasPool');
var Class = require('../utils/Class');
var Config = require('./Config');
var CreateDOMContainer = require('./CreateDOMContainer');
var CreateRenderer = require('./CreateRenderer');
var DataManager = require('../data/DataManager');
var DebugHeader = require('./DebugHeader');
@ -68,6 +69,20 @@ var Game = new Class({
*/
this.renderer = null;
/**
* A reference to an HTML Div Element used as a DOM Element Container.
*
* Only set if `createDOMContainer` is `true` in the game config (by default it is `false`) and
* if you provide a parent element to insert the Phaser Game inside.
*
* See the DOM Element Game Object for more details.
*
* @name Phaser.Game#domContainer
* @type {HTMLDivElement}
* @since 3.12.0
*/
this.domContainer = null;
/**
* A reference to the HTML Canvas Element that Phaser uses to render the game.
* This is created automatically by Phaser unless you provide a `canvas` property
@ -305,6 +320,8 @@ var Game = new Class({
CreateRenderer(this);
CreateDOMContainer(this);
DebugHeader(this);
AddToDOM(this.canvas, this.config.parent);
@ -611,6 +628,12 @@ var Game = new Class({
this.config.width = width;
this.config.height = height;
if (this.domContainer)
{
this.domContainer.style.width = width + 'px';
this.domContainer.style.height = height + 'px';
}
this.renderer.resize(width, height);
this.input.resize();
@ -666,6 +689,11 @@ var Game = new Class({
}
}
if (this.domContainer)
{
this.domContainer.parentNode.removeChild(this.domContainer);
}
this.loop.destroy();
this.pendingDestroy = false;

72
src/boot/ScaleManager.js Normal file
View file

@ -0,0 +1,72 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Class = require('../utils/Class');
var GetValue = require('../utils/object/GetValue');
/*
scale: {
width: 800,
height: 600,
resolution: window.devicePixelRatio,
},
Canvas width / height in the element
Canvas CSS width / height in the style
Detect orientation
Lock orientation (Android only?)
Full-screen support
Scale Mode -
*/
/**
* @classdesc
* [description]
*
* @class ScaleManager
* @memberOf Phaser.Boot
* @constructor
* @since 3.12.0
*
* @param {Phaser.Game} game - A reference to the Phaser.Game instance.
* @param {ScaleManagerConfig} config
*/
var ScaleManager = new Class({
initialize:
function ScaleManager (game, config)
{
/**
* A reference to the Phaser.Game instance.
*
* @name Phaser.Boot.ScaleManager#game
* @type {Phaser.Game}
* @readOnly
* @since 3.12.0
*/
this.game = game;
},
/**
* Destroys the ScaleManager.
*
* @method Phaser.Boot.ScaleManager#destroy
* @since 3.12.0
*/
destroy: function ()
{
this.game = null;
}
});
module.exports = ScaleManager;

View file

@ -102,6 +102,15 @@ var CacheManager = new Class({
*/
this.text = new BaseCache();
/**
* A Cache storing all html files, typically added via the Loader.
*
* @name Phaser.Cache.CacheManager#html
* @type {Phaser.Cache.BaseCache}
* @since 3.12.0
*/
this.html = new BaseCache();
/**
* A Cache storing all WaveFront OBJ files, typically added via the Loader.
*
@ -181,6 +190,7 @@ var CacheManager = new Class({
'shader',
'audio',
'text',
'html',
'obj',
'tilemap',
'xml'

View file

@ -122,9 +122,10 @@ var Camera = new Class({
*
* @name Phaser.Cameras.Scene2D.Camera#x
* @type {number}
* @private
* @since 3.0.0
*/
this.x = x;
this._x = x;
/**
* The y position of the Camera, relative to the top-left of the game canvas.
@ -133,9 +134,60 @@ var Camera = new Class({
*
* @name Phaser.Cameras.Scene2D.Camera#y
* @type {number}
* @private
* @since 3.0.0
*/
this.y = y;
this._y = y;
/**
* The resolution of the Game, used in most Camera calculations.
*
* @name Phaser.Cameras.Scene2D.Camera#resolution
* @type {number}
* @readOnly
* @since 3.12.0
*/
this.resolution = 1;
/**
* Internal Camera X value multiplied by the resolution.
*
* @name Phaser.Cameras.Scene2D.Camera#_cx
* @type {number}
* @private
* @since 3.12.0
*/
this._cx = 0;
/**
* Internal Camera Y value multiplied by the resolution.
*
* @name Phaser.Cameras.Scene2D.Camera#_cy
* @type {number}
* @private
* @since 3.12.0
*/
this._cy = 0;
/**
* Internal Camera Width value multiplied by the resolution.
*
* @name Phaser.Cameras.Scene2D.Camera#_cw
* @type {number}
* @private
* @since 3.12.0
*/
this._cw = 0;
/**
* Internal Camera Height value multiplied by the resolution.
*
* @name Phaser.Cameras.Scene2D.Camera#_ch
* @type {number}
* @private
* @since 3.12.0
*/
this._ch = 0;
/**
* The width of the Camera viewport, in pixels.
@ -549,7 +601,7 @@ var Camera = new Class({
* Set the Alpha level of this Camera. The alpha controls the opacity of the Camera as it renders.
* Alpha values are provided as a float between 0, fully transparent, and 1, fully opaque.
*
* @method Phaser.GameObjects.Components.Origin#setAlpha
* @method Phaser.Cameras.Scene2D.Camera#setAlpha
* @since 3.11.0
*
* @param {number} [value=1] - The Camera alpha value.
@ -575,7 +627,7 @@ var Camera = new Class({
* Changing the origin allows you to adjust the point in the viewport from which rotation happens.
* A value of 0 would rotate from the top-left of the viewport. A value of 1 from the bottom right.
*
* @method Phaser.GameObjects.Components.Origin#setOrigin
* @method Phaser.Cameras.Scene2D.Camera#setOrigin
* @since 3.11.0
*
* @param {number} [x=0.5] - The horizontal origin value.
@ -1071,8 +1123,10 @@ var Camera = new Class({
var scrollX = this.scrollX;
var scrollY = this.scrollY;
var sx = x + ((scrollX * c - scrollY * s) * zoom);
var sy = y + ((scrollX * s + scrollY * c) * zoom);
var res = this.resolution;
var sx = x * res + ((scrollX * c - scrollY * s) * zoom);
var sy = y * res + ((scrollX * s + scrollY * c) * zoom);
/* Apply transform to point */
output.x = (sx * ima + sy * imc + ime);
@ -1541,6 +1595,7 @@ var Camera = new Class({
/**
* Sets the Scene the Camera is bound to.
* Also populates the `resolution` property and updates the internal size values.
*
* @method Phaser.Cameras.Scene2D.Camera#setScene
* @since 3.0.0
@ -1553,6 +1608,15 @@ var Camera = new Class({
{
this.scene = scene;
var res = scene.sys.game.config.resolution;
this.resolution = res;
this._cx = this._x * res;
this._cy = this._y * res;
this._cw = this._width * res;
this._ch = this._height * res;
return this;
},
@ -1874,6 +1938,56 @@ var Camera = new Class({
this.deadzone = null;
},
/**
* The x position of the Camera viewport, relative to the top-left of the game canvas.
* The viewport is the area into which the camera renders.
* To adjust the position the camera is looking at in the game world, see the `scrollX` value.
*
* @name Phaser.Cameras.Scene2D.Camera#x
* @type {number}
* @since 3.0.0
*/
x: {
get: function ()
{
return this._x;
},
set: function (value)
{
this._x = value;
this._cx = value * this.resolution;
this.dirty = true;
}
},
/**
* The y position of the Camera viewport, relative to the top-left of the game canvas.
* The viewport is the area into which the camera renders.
* To adjust the position the camera is looking at in the game world, see the `scrollY` value.
*
* @name Phaser.Cameras.Scene2D.Camera#y
* @type {number}
* @since 3.0.0
*/
y: {
get: function ()
{
return this._y;
},
set: function (value)
{
this._y = value;
this._cy = value * this.resolution;
this.dirty = true;
}
},
/**
* The width of the Camera viewport, in pixels.
*
@ -1894,6 +2008,7 @@ var Camera = new Class({
set: function (value)
{
this._width = value;
this._cw = value * this.resolution;
this.dirty = true;
}
@ -1919,6 +2034,7 @@ var Camera = new Class({
set: function (value)
{
this._height = value;
this._ch = value * this.resolution;
this.dirty = true;
}

View file

@ -337,7 +337,7 @@ var Fade = new Class({
var camera = this.camera;
ctx.fillStyle = 'rgba(' + this.red + ',' + this.green + ',' + this.blue + ',' + this.alpha + ')';
ctx.fillRect(camera.x, camera.y, camera.width, camera.height);
ctx.fillRect(camera._cx, camera._cy, camera._cw, camera._ch);
return true;
},
@ -367,7 +367,7 @@ var Fade = new Class({
pipeline.batchFillRect(
0, 0, 1, 1, 0,
camera.x, camera.y, camera.width, camera.height,
camera._cx, camera._cy, camera._cw, camera._ch,
getTintFunction(red, green, blue, 1),
this.alpha,
1, 0, 0, 1, 0, 0,

View file

@ -284,7 +284,7 @@ var Flash = new Class({
var camera = this.camera;
ctx.fillStyle = 'rgba(' + this.red + ',' + this.green + ',' + this.blue + ',' + this.alpha + ')';
ctx.fillRect(camera.x, camera.y, camera.width, camera.height);
ctx.fillRect(camera._cx, camera._cy, camera._cw, camera._ch);
return true;
},
@ -314,7 +314,7 @@ var Flash = new Class({
pipeline.batchFillRect(
0, 0, 1, 1, 0,
camera.x, camera.y, camera.width, camera.height,
camera._cx, camera._cy, camera._cw, camera._ch,
getTintFunction(red, green, blue, 1),
this.alpha,
1, 0, 0, 1, 0, 0,

View file

@ -261,8 +261,8 @@ var Shake = new Class({
if (this._elapsed < this.duration)
{
var intensity = this.intensity;
var width = this.camera.width;
var height = this.camera.height;
var width = this.camera._cw;
var height = this.camera._ch;
var zoom = this.camera.zoom;
this._offsetX = (Math.random() * intensity.x * width * 2 - intensity.x * width) * zoom;

View file

@ -391,7 +391,7 @@ var GameObject = new Class({
* removed from the Input Manager and cleared from this Game Object.
*
* If you wish to re-enable this Game Object at a later date you will need to
* re-create its InteractiveOobject by calling `setInteractive` again.
* re-create its InteractiveObject by calling `setInteractive` again.
*
* If you wish to only temporarily stop an object from receiving input then use
* `disableInteractive` instead, as that toggles the interactive state, where-as
@ -436,15 +436,18 @@ var GameObject = new Class({
/**
* Compares the renderMask with the renderFlags to see if this Game Object will render or not.
* Also checks the Game Object against the given Cameras exclusion list.
*
* @method Phaser.GameObjects.GameObject#willRender
* @since 3.0.0
*
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera to check against this Game Object.
*
* @return {boolean} True if the Game Object should be rendered, otherwise false.
*/
willRender: function ()
willRender: function (camera)
{
return (GameObject.RENDER_MASK === this.renderFlags);
return !(GameObject.RENDER_MASK !== this.renderFlags || (this.cameraFilter > 0 && (this.cameraFilter & camera.id)));
},
/**

View file

@ -4,8 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../../GameObject');
/**
* Renders this Game Object with the Canvas Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
@ -26,7 +24,7 @@ var DynamicBitmapTextCanvasRenderer = function (renderer, src, interpolationPerc
var text = src.text;
var textLength = text.length;
if (GameObject.RENDER_MASK !== src.renderFlags || textLength === 0 || (src.cameraFilter > 0 && (src.cameraFilter & camera.id)))
if (textLength === 0)
{
return;
}

View file

@ -4,7 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../../GameObject');
var Utils = require('../../../renderer/webgl/Utils');
/**
@ -27,7 +26,7 @@ var DynamicBitmapTextWebGLRenderer = function (renderer, src, interpolationPerce
var text = src.text;
var textLength = text.length;
if (GameObject.RENDER_MASK !== src.renderFlags || textLength === 0 || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
if (textLength === 0)
{
return;
}

View file

@ -4,8 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../../GameObject');
/**
* Renders this Game Object with the Canvas Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
@ -26,7 +24,7 @@ var BitmapTextCanvasRenderer = function (renderer, src, interpolationPercentage,
var text = src._text;
var textLength = text.length;
if (GameObject.RENDER_MASK !== src.renderFlags || textLength === 0 || (src.cameraFilter > 0 && (src.cameraFilter & camera.id)))
if (textLength === 0)
{
return;
}

View file

@ -4,7 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../../GameObject');
var Utils = require('../../../renderer/webgl/Utils');
/**
@ -27,7 +26,7 @@ var BitmapTextWebGLRenderer = function (renderer, src, interpolationPercentage,
var text = src._text;
var textLength = text.length;
if (GameObject.RENDER_MASK !== src.renderFlags || textLength === 0 || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
if (textLength === 0)
{
return;
}

View file

@ -4,8 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../GameObject');
/**
* Renders this Game Object with the Canvas Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
@ -25,7 +23,7 @@ var BlitterCanvasRenderer = function (renderer, src, interpolationPercentage, ca
{
var list = src.getRenderList();
if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera.id)) || list.length === 0)
if (list.length === 0)
{
return;
}

View file

@ -4,7 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../GameObject');
var Utils = require('../../renderer/webgl/Utils');
/**
@ -24,7 +23,9 @@ var Utils = require('../../renderer/webgl/Utils');
*/
var BlitterWebGLRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
{
if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
var list = src.getRenderList();
if (list.length === 0)
{
return;
}
@ -48,7 +49,6 @@ var BlitterWebGLRenderer = function (renderer, src, interpolationPercentage, cam
cameraScrollY = 0;
}
var list = src.getRenderList();
var blitterX = src.x - cameraScrollX;
var blitterY = src.y - cameraScrollY;
var prevTextureSourceIndex = -1;

View file

@ -45,16 +45,6 @@ var TextureCrop = {
*/
isCropped: false,
/**
* The internal crop data object, as used by `setCrop` and passed to the `Frame.setCropUVs` method.
*
* @name Phaser.GameObjects.Components.TextureCrop#isCropped
* @type {object}
* @private
* @since 3.11.0
*/
_crop: { u0: 0, v0: 0, u1: 0, v1: 0, width: 0, height: 0, x: 0, y: 0, flipX: false, flipY: false, cx: 0, cy: 0, cw: 0, ch: 0 },
/**
* Applies a crop to a texture based Game Object, such as a Sprite or Image.
*

View file

@ -727,6 +727,21 @@ var TransformMatrix = new Class({
return this;
},
/**
* Returns a string that can be used in a CSS Transform call as a `matrix` property.
*
* @method Phaser.GameObjects.Components.TransformMatrix#getCSSMatrix
* @since 3.12.0
*
* @return {string} A string containing the CSS Transform matrix values.
*/
getCSSMatrix: function ()
{
var m = this.matrix;
return 'matrix(' + m[0] + ',' + m[1] + ',' + m[2] + ',' + m[3] + ',' + m[4] + ',' + m[5] + ')';
},
/**
* Destroys this Transform Matrix.
*

View file

@ -5,8 +5,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../GameObject');
/**
* Renders this Game Object with the Canvas Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
@ -24,12 +22,13 @@ var GameObject = require('../GameObject');
*/
var ContainerCanvasRenderer = function (renderer, container, interpolationPercentage, camera, parentMatrix)
{
if (GameObject.RENDER_MASK !== container.renderFlags || (container.cameraFilter > 0 && (container.cameraFilter & camera._id)))
var children = container.list;
if (children.length === 0)
{
return;
}
var children = container.list;
var transformMatrix = container.localTransform;
if (parentMatrix === undefined)
@ -49,9 +48,9 @@ var ContainerCanvasRenderer = function (renderer, container, interpolationPercen
var scrollFactorX = container.scrollFactorX;
var scrollFactorY = container.scrollFactorY;
for (var index = 0; index < children.length; ++index)
for (var i = 0; i < children.length; i++)
{
var child = children[index];
var child = children[i];
var childAlpha = child._alpha;
var childScrollFactorX = child.scrollFactorX;
var childScrollFactorY = child.scrollFactorY;

View file

@ -5,8 +5,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../GameObject');
/**
* Renders this Game Object with the WebGL Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
@ -24,12 +22,13 @@ var GameObject = require('../GameObject');
*/
var ContainerWebGLRenderer = function (renderer, container, interpolationPercentage, camera, parentMatrix)
{
if (GameObject.RENDER_MASK !== container.renderFlags || (container.cameraFilter > 0 && (container.cameraFilter & camera._id)))
var children = container.list;
if (children.length === 0)
{
return;
}
var children = container.list;
var transformMatrix = container.localTransform;
if (parentMatrix === undefined)
@ -49,9 +48,9 @@ var ContainerWebGLRenderer = function (renderer, container, interpolationPercent
var scrollFactorX = container.scrollFactorX;
var scrollFactorY = container.scrollFactorY;
for (var index = 0; index < children.length; ++index)
for (var i = 0; i < children.length; i++)
{
var child = children[index];
var child = children[i];
var childAlpha = child._alpha;
var childScrollFactorX = child.scrollFactorX;
var childScrollFactorY = child.scrollFactorY;

View file

@ -0,0 +1,35 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* Phaser Blend Modes to CSS Blend Modes Map.
*
* @name Phaser.CSSBlendModes
* @enum {string}
* @memberOf Phaser
* @readOnly
* @since 3.12.0
*/
module.exports = [
'normal',
'multiply',
'multiply',
'screen',
'overlay',
'darken',
'lighten',
'color-dodge',
'color-burn',
'hard-light',
'soft-light',
'difference',
'exclusion',
'hue',
'saturation',
'color',
'luminosity'
];

View file

@ -0,0 +1,295 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Class = require('../../utils/Class');
var Components = require('../components');
var DOMElementRender = require('./DOMElementRender');
var GameObject = require('../GameObject');
var Vector4 = require('../../math/Vector4');
/**
* @classdesc
* [description]
*
* @class DOMElement
* @extends Phaser.GameObjects.GameObject
* @memberOf Phaser.GameObjects
* @constructor
* @since 3.12.0
*
* @extends Phaser.GameObjects.Components.Alpha
* @extends Phaser.GameObjects.Components.BlendMode
* @extends Phaser.GameObjects.Components.ComputedSize
* @extends Phaser.GameObjects.Components.Depth
* @extends Phaser.GameObjects.Components.Origin
* @extends Phaser.GameObjects.Components.ScrollFactor
* @extends Phaser.GameObjects.Components.Transform
* @extends Phaser.GameObjects.Components.Visible
*
* @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time.
* @param {number} x - The horizontal position of this Game Object in the world.
* @param {number} y - The vertical position of this Game Object in the world.
* @param {(string|HTMLElement)} [element] - The DOM Element to use.
*/
var DOMElement = new Class({
Extends: GameObject,
Mixins: [
Components.Alpha,
Components.BlendMode,
Components.ComputedSize,
Components.Depth,
Components.Origin,
Components.ScrollFactor,
Components.Transform,
Components.Visible,
DOMElementRender
],
initialize:
function DOMElement (scene, x, y, element)
{
GameObject.call(this, scene, 'DOMElement');
this.parent = scene.sys.game.domContainer;
this.cache = scene.sys.cache.html;
this.node;
this.skewX = 0;
this.skewY = 0;
// https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/rotate3d
this.rotate3d = new Vector4();
this.rotate3dAngle = 'deg';
this.handler = this.dispatchNativeEvent.bind(this);
this.setPosition(x, y);
if (element)
{
this.setElement(element);
}
},
setSkew: function (x, y)
{
if (x === undefined) { x = 0; }
if (y === undefined) { y = x; }
this.skewX = x;
this.skewY = y;
return this;
},
perspective: {
get: function ()
{
return parseFloat(this.parent.style.perspective);
},
set: function (value)
{
this.parent.style.perspective = value + 'px';
}
},
setPerspective: function (value)
{
// Sets it on the DOM Container!
this.parent.style.perspective = value + 'px';
return this;
},
addListener: function (events)
{
if (this.node)
{
events = events.split(' ');
for (var i = 0; i < events.length; i++)
{
this.node.addEventListener(events[i], this.handler, false);
}
}
return this;
},
removeListener: function (events)
{
if (this.node)
{
events = events.split(' ');
for (var i = 0; i < events.length; i++)
{
this.node.removeEventListener(events[i], this.handler);
}
}
return this;
},
dispatchNativeEvent: function (event)
{
this.emit(event.type, event);
},
setElement: function (element)
{
var target;
if (typeof element === 'string')
{
target = document.getElementById(element);
}
else if (typeof element === 'object' && element.nodeType === 1)
{
target = element;
}
if (!target)
{
return;
}
this.node = target;
target.style.zIndex = '0';
target.style.display = 'inline';
target.style.position = 'absolute';
// Node handler
target.phaser = this;
if (this.parent)
{
this.parent.appendChild(target);
}
var nodeBounds = target.getBoundingClientRect();
this.setSize(nodeBounds.width || 0, nodeBounds.height || 0);
return this;
},
createFromCache: function (key, elementType)
{
return this.createFromHTML(this.cache.get(key), elementType);
},
createFromHTML: function (html, elementType)
{
if (elementType === undefined) { elementType = 'div'; }
var element = document.createElement(elementType);
this.node = element;
element.style.zIndex = '0';
element.style.display = 'inline';
element.style.position = 'absolute';
// Node handler
element.phaser = this;
if (this.parent)
{
this.parent.appendChild(element);
}
element.innerHTML = html;
var nodeBounds = element.getBoundingClientRect();
this.setSize(nodeBounds.width || 0, nodeBounds.height || 0);
return this;
},
getChildByProperty: function (property, value)
{
if (this.node)
{
var children = this.node.querySelectorAll('*');
for (var i = 0; i < children.length; i++)
{
if (children[i][property] === value)
{
return children[i];
}
}
}
return null;
},
getChildByID: function (id)
{
return this.getChildByProperty('id', id);
},
getChildByName: function (name)
{
return this.getChildByProperty('name', name);
},
setText: function (text)
{
if (this.node)
{
this.node.innerText = text;
}
return this;
},
setHTML: function (html)
{
if (this.node)
{
this.node.innerHTML = html;
}
return this;
},
/**
* Compares the renderMask with the renderFlags to see if this Game Object will render or not.
*
* DOMElements always return `true` as they need to still set values during the render pass, even if not visible.
*
* @method Phaser.GameObjects.DOMElement#willRender
* @since 3.12.0
*
* @return {boolean} True if the Game Object should be rendered, otherwise false.
*/
willRender: function ()
{
return true;
},
destroy: function ()
{
}
});
module.exports = DOMElement;

View file

@ -0,0 +1,69 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var CSSBlendModes = require('./CSSBlendModes');
var GameObject = require('../GameObject');
/**
* Renders this Game Object with the WebGL Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
* This method should not be called directly. It is a utility function of the Render module.
*
* @method Phaser.GameObjects.DOMElement#renderWebGL
* @since 3.12.0
* @private
*
* @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - A reference to the current active renderer.
* @param {Phaser.GameObjects.DOMElement} src - The Game Object being rendered in this call.
* @param {number} interpolationPercentage - Reserved for future use and custom pipelines.
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object.
*/
var DOMElementCSSRenderer = function (renderer, src, interpolationPercentage, camera)
{
var node = src.node;
if (!node || GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera.id)))
{
if (node)
{
node.style.display = 'none';
}
return;
}
var camMatrix = renderer.pipelines.TextureTintPipeline._tempMatrix1;
var spriteMatrix = renderer.pipelines.TextureTintPipeline._tempMatrix2;
var calcMatrix = renderer.pipelines.TextureTintPipeline._tempMatrix3;
var x = src.originX * src.width;
var y = src.originY * src.height;
spriteMatrix.applyITRS(src.x - x - (camera.scrollX * src.scrollFactorX), src.y - y - (camera.scrollY * src.scrollFactorY), src.rotation, src.scaleX, src.scaleY);
camMatrix.copyFrom(camera.matrix);
camMatrix.multiply(spriteMatrix, calcMatrix);
node.style.display = 'block';
node.style.opacity = src.alpha;
node.style.zIndex = src._depth;
node.style.pointerEvents = 'auto';
node.style.mixBlendMode = CSSBlendModes[src._blendMode];
// https://developer.mozilla.org/en-US/docs/Web/CSS/transform
node.style.transform =
calcMatrix.getCSSMatrix() +
' skew(' + src.skewX + 'rad, ' + src.skewY + 'rad)' +
' rotate3d(' + src.rotate3d.x + ',' + src.rotate3d.y + ',' + src.rotate3d.z + ',' + src.rotate3d.w + src.rotate3dAngle + ')';
// node.style.transform = calcMatrix.getCSSMatrix();
node.style.transformOrigin = (100 * src.originX) + '% ' + (100 * src.originY) + '%';
};
module.exports = DOMElementCSSRenderer;

View file

@ -0,0 +1,35 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var DOMElement = require('./DOMElement');
var GameObjectFactory = require('../GameObjectFactory');
/**
* Creates a new Image Game Object and adds it to the Scene.
*
* Note: This method will only be available if the Image Game Object has been built into Phaser.
*
* @method Phaser.GameObjects.GameObjectFactory#dom
* @since 3.12.0
*
* @param {number} x - The horizontal position of this Game Object in the world.
* @param {number} y - The vertical position of this Game Object in the world.
* @param {string} element - The DOM element.
*
* @return {Phaser.GameObjects.DOMElement} The Game Object that was created.
*/
GameObjectFactory.register('dom', function (x, y, element)
{
return this.displayList.add(new DOMElement(this.scene, x, y, element));
});
// When registering a factory function 'this' refers to the GameObjectFactory context.
//
// There are several properties available to use:
//
// this.scene - a reference to the Scene that owns the GameObjectFactory
// this.displayList - a reference to the Display List the Scene owns
// this.updateList - a reference to the Update List the Scene owns

View file

@ -0,0 +1,25 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var renderWebGL = require('../../utils/NOOP');
var renderCanvas = require('../../utils/NOOP');
if (typeof WEBGL_RENDERER)
{
renderWebGL = require('./DOMElementCSSRenderer');
}
if (typeof CANVAS_RENDERER)
{
renderCanvas = require('./DOMElementCSSRenderer');
}
module.exports = {
renderWebGL: renderWebGL,
renderCanvas: renderCanvas
};

View file

@ -5,7 +5,6 @@
*/
var Commands = require('./Commands');
var GameObject = require('../GameObject');
/**
* Renders this Game Object with the Canvas Renderer to the given Camera.
@ -26,7 +25,10 @@ var GameObject = require('../GameObject');
*/
var GraphicsCanvasRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix, renderTargetCtx, allowClip)
{
if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera.id)))
var commandBuffer = src.commandBuffer;
var commandBufferLength = commandBuffer.length;
if (commandBufferLength === 0)
{
return;
}
@ -38,7 +40,6 @@ var GraphicsCanvasRenderer = function (renderer, src, interpolationPercentage, c
var srcScaleX = src.scaleX;
var srcScaleY = src.scaleY;
var srcRotation = src.rotation;
var commandBuffer = src.commandBuffer;
var ctx = renderTargetCtx || renderer.currentContext;
var lineAlpha = 1.0;
var fillAlpha = 1.0;
@ -92,7 +93,7 @@ var GraphicsCanvasRenderer = function (renderer, src, interpolationPercentage, c
ctx.fillStyle = '#fff';
ctx.globalAlpha = src.alpha;
for (var index = 0, length = commandBuffer.length; index < length; ++index)
for (var index = 0; index < commandBufferLength; ++index)
{
var commandID = commandBuffer[index];

View file

@ -4,8 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../GameObject');
/**
* Renders this Game Object with the WebGL Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
@ -16,19 +14,22 @@ var GameObject = require('../GameObject');
* @private
*
* @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - A reference to the current active WebGL renderer.
* @param {Phaser.GameObjects.Graphics} graphics - The Game Object being rendered in this call.
* @param {Phaser.GameObjects.Graphics} src - The Game Object being rendered in this call.
* @param {number} interpolationPercentage - Reserved for future use and custom pipelines.
* @param {Phaser.Cameras.Scene2D.Camera} camera - The Camera that is rendering the Game Object.
* @param {Phaser.GameObjects.Components.TransformMatrix} parentMatrix - This transform matrix is defined if the game object is nested
*/
var GraphicsWebGLRenderer = function (renderer, graphics, interpolationPercentage, camera, parentMatrix)
var GraphicsWebGLRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
{
if (GameObject.RENDER_MASK !== graphics.renderFlags || (graphics.cameraFilter > 0 && (graphics.cameraFilter & camera._id)))
var commandBuffer = src.commandBuffer;
var commandBufferLength = commandBuffer.length;
if (commandBufferLength === 0)
{
return;
}
this.pipeline.batchGraphics(this, camera, parentMatrix);
this.pipeline.batchGraphics(src, camera, parentMatrix);
};
module.exports = GraphicsWebGLRenderer;

View file

@ -75,6 +75,16 @@ var Image = new Class({
{
GameObject.call(this, scene, 'Image');
/**
* The internal crop data object, as used by `setCrop` and passed to the `Frame.setCropUVs` method.
*
* @name Phaser.GameObjects.Image#_crop
* @type {object}
* @private
* @since 3.11.0
*/
this._crop = { u0: 0, v0: 0, u1: 0, v1: 0, width: 0, height: 0, x: 0, y: 0, flipX: false, flipY: false, cx: 0, cy: 0, cw: 0, ch: 0 };
this.setTexture(texture, frame);
this.setPosition(x, y);
this.setSizeToFrame();

View file

@ -4,8 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../GameObject');
/**
* Renders this Game Object with the Canvas Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
@ -23,11 +21,6 @@ var GameObject = require('../GameObject');
*/
var ImageCanvasRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
{
if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera.id)))
{
return;
}
renderer.drawImage(src, camera, parentMatrix);
};

View file

@ -4,8 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../GameObject');
/**
* Renders this Game Object with the WebGL Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
@ -23,11 +21,6 @@ var GameObject = require('../GameObject');
*/
var ImageWebGLRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
{
if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera.id)))
{
return;
}
this.pipeline.batchSprite(src, camera, parentMatrix);
};

View file

@ -23,6 +23,7 @@ var GameObjects = {
BitmapText: require('./bitmaptext/static/BitmapText'),
Blitter: require('./blitter/Blitter'),
Container: require('./container/Container'),
DOMElement: require('./domelement/DOMElement'),
DynamicBitmapText: require('./bitmaptext/dynamic/DynamicBitmapText'),
Graphics: require('./graphics/Graphics.js'),
Group: require('./group/Group'),
@ -42,6 +43,7 @@ var GameObjects = {
Factories: {
Blitter: require('./blitter/BlitterFactory'),
Container: require('./container/ContainerFactory'),
DOMElement: require('./domelement/DOMElementFactory'),
DynamicBitmapText: require('./bitmaptext/dynamic/DynamicBitmapTextFactory'),
Graphics: require('./graphics/GraphicsFactory'),
Group: require('./group/GroupFactory'),

View file

@ -4,7 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../GameObject');
var Utils = require('../../renderer/webgl/Utils');
/**
@ -24,11 +23,6 @@ var Utils = require('../../renderer/webgl/Utils');
*/
var MeshWebGLRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
{
if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera.id)))
{
return;
}
var pipeline = this.pipeline;
renderer.setPipeline(pipeline, src);

View file

@ -4,8 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../GameObject');
/**
* Renders this Game Object with the Canvas Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
@ -24,8 +22,9 @@ var GameObject = require('../GameObject');
var ParticleManagerCanvasRenderer = function (renderer, emitterManager, interpolationPercentage, camera, parentMatrix)
{
var emitters = emitterManager.emitters.list;
var emittersLength = emitters.length;
if (emitters.length === 0 || GameObject.RENDER_MASK !== emitterManager.renderFlags || (emitterManager.cameraFilter > 0 && (emitterManager.cameraFilter & camera._id)))
if (emittersLength === 0)
{
return;
}
@ -41,7 +40,7 @@ var ParticleManagerCanvasRenderer = function (renderer, emitterManager, interpol
ctx.transform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
}
for (var i = 0; i < emitters.length; i++)
for (var i = 0; i < emittersLength; i++)
{
var emitter = emitters[i];

View file

@ -4,8 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../GameObject');
/**
* Renders this Game Object with the WebGL Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
@ -24,8 +22,9 @@ var GameObject = require('../GameObject');
var ParticleManagerWebGLRenderer = function (renderer, emitterManager, interpolationPercentage, camera, parentMatrix)
{
var emitters = emitterManager.emitters.list;
var emittersLength = emitters.length;
if (emitters.length === 0 || GameObject.RENDER_MASK !== emitterManager.renderFlags || (emitterManager.cameraFilter > 0 && (emitterManager.cameraFilter & camera._id)))
if (emittersLength === 0)
{
return;
}
@ -43,7 +42,7 @@ var ParticleManagerWebGLRenderer = function (renderer, emitterManager, interpola
pipeline.setTexture2D(texture, 0);
for (var e = 0; e < emitters.length; e++)
for (var e = 0; e < emittersLength; e++)
{
var emitter = emitters[e];
var particles = emitter.alive;

View file

@ -4,8 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../GameObject');
/**
* Renders this Game Object with the Canvas Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
@ -23,11 +21,6 @@ var GameObject = require('../GameObject');
*/
var RenderTextureCanvasRenderer = function (renderer, renderTexture, interpolationPercentage, camera, parentMatrix)
{
if (GameObject.RENDER_MASK !== renderTexture.renderFlags || (renderTexture.cameraFilter > 0 && (renderTexture.cameraFilter & camera._id)))
{
return;
}
var ctx = renderer.currentContext;
// Alpha

View file

@ -4,7 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../GameObject');
var Utils = require('../../renderer/webgl/Utils');
/**
@ -24,11 +23,6 @@ var Utils = require('../../renderer/webgl/Utils');
*/
var RenderTextureWebGLRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
{
if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera._id)))
{
return;
}
var getTint = Utils.getTintAppendFloatAlpha;
this.pipeline.batchTexture(

View file

@ -78,6 +78,16 @@ var Sprite = new Class({
{
GameObject.call(this, scene, 'Sprite');
/**
* The internal crop data object, as used by `setCrop` and passed to the `Frame.setCropUVs` method.
*
* @name Phaser.GameObjects.Sprite#_crop
* @type {object}
* @private
* @since 3.11.0
*/
this._crop = { u0: 0, v0: 0, u1: 0, v1: 0, width: 0, height: 0, x: 0, y: 0, flipX: false, flipY: false, cx: 0, cy: 0, cw: 0, ch: 0 };
/**
* The Animation Controller of this Sprite.
*

View file

@ -4,8 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../GameObject');
/**
* Renders this Game Object with the Canvas Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
@ -23,11 +21,6 @@ var GameObject = require('../GameObject');
*/
var SpriteCanvasRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
{
if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera.id)))
{
return;
}
renderer.drawImage(src, camera, parentMatrix);
};

View file

@ -4,8 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../GameObject');
/**
* Renders this Game Object with the WebGL Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
@ -23,11 +21,6 @@ var GameObject = require('../GameObject');
*/
var SpriteWebGLRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
{
if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera.id)))
{
return;
}
this.pipeline.batchSprite(src, camera, parentMatrix);
};

View file

@ -11,7 +11,7 @@
* @since 3.0.0
*
* @param {Phaser.GameObjects.Text} text - The Text object to calculate the size from.
* @param {TextMetrics} size - The Text metrics to use when calculating the size.
* @param {BitmapTextMetrics} size - The Text metrics to use when calculating the size.
* @param {array} lines - The lines of text to calculate the size from.
*
* @return {object} An object containing dimensions of the Text object.

View file

@ -40,6 +40,7 @@ var propertyMap = {
maxLines: [ 'maxLines', 0 ],
fixedWidth: [ 'fixedWidth', 0 ],
fixedHeight: [ 'fixedHeight', 0 ],
resolution: [ 'resolution', 0 ],
rtl: [ 'rtl', false ],
testString: [ 'testString', '|MÉqgy' ],
baselineX: [ 'baselineX', 1.2 ],
@ -53,7 +54,7 @@ var propertyMap = {
/**
* Font metrics for a Text Style object.
*
* @typedef {object} TextMetrics
* @typedef {object} BitmapTextMetrics
*
* @property {number} ascent - The ascent of the font.
* @property {number} descent - The descent of the font.
@ -259,6 +260,17 @@ var TextStyle = new Class({
*/
this.fixedHeight;
/**
* The resolution the text is rendered to its internal canvas at.
* The default is 0, which means it will use the resolution set in the Game Config.
*
* @name Phaser.GameObjects.Text.TextStyle#resolution
* @type {number}
* @default 0
* @since 3.12.0
*/
this.resolution;
/**
* Whether the text should render right to left.
*
@ -675,6 +687,29 @@ var TextStyle = new Class({
return this.update(false);
},
/**
* Set the resolution used by the Text object.
*
* By default it will be set to match the resolution set in the Game Config,
* but you can override it via this method. It allows for much clearer text on High DPI devices,
* at the cost of memory because it uses larger internal Canvas textures for the Text.
*
* Please use with caution, as the more high res Text you have, the more memory it uses up.
*
* @method Phaser.GameObjects.Text.TextStyle#setResolution
* @since 3.12.0
*
* @param {number} value - The resolution for this Text object to use.
*
* @return {Phaser.GameObjects.Text} The parent Text object.
*/
setResolution: function (value)
{
this.resolution = value;
return this.update(false);
},
/**
* Set the stroke settings.
*
@ -929,7 +964,7 @@ var TextStyle = new Class({
* @method Phaser.GameObjects.Text.TextStyle#getTextMetrics
* @since 3.0.0
*
* @return {TextMetrics} The text metrics.
* @return {BitmapTextMetrics} The text metrics.
*/
getTextMetrics: function ()
{

View file

@ -141,16 +141,6 @@ var Text = new Class({
*/
this.text = '';
/**
* The resolution of the text.
*
* @name Phaser.GameObjects.Text#resolution
* @type {number}
* @default 1
* @since 3.0.0
*/
this.resolution = 1;
/**
* Specify a padding value which is added to the line width and height when calculating the Text size.
* Allows you to add extra spacing if the browser is unable to accurately determine the true font dimensions.
@ -201,6 +191,12 @@ var Text = new Class({
*/
this.dirty = false;
// If resolution wasn't set, then we get it from the game config
if (this.style.resolution === 0)
{
this.style.resolution = scene.sys.game.config.resolution;
}
this.initRTL();
if (style && style.padding)
@ -857,6 +853,29 @@ var Text = new Class({
return this.style.setAlign(align);
},
/**
* Set the resolution used by this Text object.
*
* By default it will be set to match the resolution set in the Game Config,
* but you can override it via this method, or by specifying it in the Text style configuration object.
*
* It allows for much clearer text on High DPI devices, at the cost of memory because it uses larger
* internal Canvas textures for the Text.
*
* Therefore, please use with caution, as the more high res Text you have, the more memory it uses.
*
* @method Phaser.GameObjects.Text#setResolution
* @since 3.12.0
*
* @param {number} value - The resolution for this Text object to use.
*
* @return {Phaser.GameObjects.Text} This Text object.
*/
setResolution: function (value)
{
return this.style.setResolution(value);
},
/**
* Set the text padding.
*
@ -951,7 +970,7 @@ var Text = new Class({
var canvas = this.canvas;
var context = this.context;
var style = this.style;
var resolution = this.resolution;
var resolution = style.resolution;
var size = style.metrics;
style.syncFont(canvas, context);
@ -1004,7 +1023,7 @@ var Text = new Class({
context.save();
// context.scale(resolution, resolution);
context.scale(resolution, resolution);
if (style.backgroundColor)
{
@ -1105,7 +1124,6 @@ var Text = new Class({
autoRound: this.autoRound,
text: this.text,
style: this.style.toJSON(),
resolution: this.resolution,
padding: {
left: this.padding.left,
right: this.padding.right,

View file

@ -4,8 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../../GameObject');
/**
* Renders this Game Object with the Canvas Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
@ -23,7 +21,7 @@ var GameObject = require('../../GameObject');
*/
var TextCanvasRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
{
if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera.id)) || src.text === '')
if (src.text === '')
{
return;
}
@ -89,7 +87,7 @@ var TextCanvasRenderer = function (renderer, src, interpolationPercentage, camer
ctx.scale(src.flipX ? -1 : 1, src.flipY ? -1 : 1);
ctx.drawImage(canvas, 0, 0, canvas.width, canvas.height, -src.displayOriginX, -src.displayOriginY, canvas.width, canvas.height);
ctx.drawImage(canvas, 0, 0, canvas.width, canvas.height, -src.displayOriginX, -src.displayOriginY, canvas.width / src.style.resolution, canvas.height / src.style.resolution);
ctx.restore();
};

View file

@ -4,7 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../../GameObject');
var Utils = require('../../../renderer/webgl/Utils');
/**
@ -24,7 +23,7 @@ var Utils = require('../../../renderer/webgl/Utils');
*/
var TextWebGLRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
{
if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera.id)) || src.text === '')
if (src.text === '')
{
return;
}
@ -42,7 +41,7 @@ var TextWebGLRenderer = function (renderer, src, interpolationPercentage, camera
src.canvasTexture,
src.canvasTexture.width, src.canvasTexture.height,
src.x, src.y,
src.canvasTexture.width, src.canvasTexture.height,
src.canvasTexture.width / src.style.resolution, src.canvasTexture.height / src.style.resolution,
src.scaleX, src.scaleY,
src.rotation,
src.flipX, src.flipY,

View file

@ -4,8 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../GameObject');
/**
* Renders this Game Object with the Canvas Renderer to the given Camera.
* The object will not render if any of its renderFlags are set or it is being actively filtered out by the Camera.
@ -23,11 +21,6 @@ var GameObject = require('../GameObject');
*/
var TileSpriteCanvasRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
{
if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera.id)))
{
return;
}
var ctx = renderer.currentContext;
var frame = src.frame;

View file

@ -4,7 +4,6 @@
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var GameObject = require('../GameObject');
var Utils = require('../../renderer/webgl/Utils');
/**
@ -24,11 +23,6 @@ var Utils = require('../../renderer/webgl/Utils');
*/
var TileSpriteWebGLRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix)
{
if (GameObject.RENDER_MASK !== src.renderFlags || (src.cameraFilter > 0 && (src.cameraFilter & camera.id)))
{
return;
}
src.updateTileTexture();
var getTint = Utils.getTintAppendFloatAlpha;

View file

@ -1108,15 +1108,20 @@ var InputManager = new Class({
if (output === undefined) { output = this._tempHitTest; }
var tempPoint = this._tempPoint;
var cameraW = camera.width;
var cameraH = camera.height;
var cx = camera._cx;
var cy = camera._cy;
var cw = camera._cw;
var ch = camera._ch;
var csx = camera.scrollX;
var csy = camera.scrollY;
output.length = 0;
var x = pointer.x;
var y = pointer.y;
if (!(x >= camera.x && y >= camera.y && x <= camera.x + cameraW && y <= camera.y + cameraH))
if (!(x >= cx && y >= cy && x <= cx + cw && y <= cy + ch))
{
return output;
}
@ -1127,13 +1132,8 @@ var InputManager = new Class({
pointer.worldX = tempPoint.x;
pointer.worldY = tempPoint.y;
// Disable until fixed.
// var culledGameObjects = camera.cull(gameObjects);
var point = { x: 0, y: 0 };
var res = this.game.config.resolution;
var matrix = this._tempMatrix;
for (var i = 0; i < gameObjects.length; i++)
@ -1145,8 +1145,8 @@ var InputManager = new Class({
continue;
}
var px = tempPoint.x * res + (camera.scrollX * gameObject.scrollFactorX) - camera.scrollX;
var py = tempPoint.y * res + (camera.scrollY * gameObject.scrollFactorY) - camera.scrollY;
var px = tempPoint.x + (csx * gameObject.scrollFactorX) - csx;
var py = tempPoint.y + (csy * gameObject.scrollFactorY) - csy;
if (gameObject.parentContainer)
{
@ -1245,8 +1245,8 @@ var InputManager = new Class({
* @since 3.10.0
*
* @param {Phaser.Input.Pointer} pointer - The Pointer to transform the values for.
*
* @return {number} The translated value.
* @param {number} pageX - The Page X value.
* @param {number} pageY - The Page Y value.
*/
transformPointer: function (pointer, pageX, pageY)
{
@ -1254,7 +1254,6 @@ var InputManager = new Class({
pointer.prevPosition.x = pointer.x;
pointer.prevPosition.y = pointer.y;
// Set the new position
pointer.x = (pageX - this.bounds.left) * this.scale.x;
pointer.y = (pageY - this.bounds.top) * this.scale.y;
},

View file

@ -97,7 +97,7 @@ var AudioFile = new Class({
function (e)
{
// eslint-disable-next-line no-console
console.error('Error decoding audio: ' + this.key + ' - ', e.message);
console.error('Error decoding audio: ' + this.key + ' - ', e ? e.message : null);
_this.onProcessError();
}

View file

@ -14,12 +14,10 @@ var IsPlainObject = require('../../utils/object/IsPlainObject');
/**
* @typedef {object} Phaser.Loader.FileTypes.HTMLFileConfig
*
* @property {string} key - The key of the file. Must be unique within both the Loader and the Texture Manager.
* @property {string} key - The key of the file. Must be unique within both the Loader and the Text Cache.
* @property {string} [url] - The absolute or relative URL to load the file from.
* @property {string} [extension='html'] - The default file extension to use if no url is provided.
* @property {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file.
* @property {integer} [width=512] - The width of the texture the HTML will be rendered to.
* @property {integer} [height=512] - The height of the texture the HTML will be rendered to.
*/
/**
@ -34,13 +32,11 @@ var IsPlainObject = require('../../utils/object/IsPlainObject');
* @extends Phaser.Loader.File
* @memberOf Phaser.Loader.FileTypes
* @constructor
* @since 3.0.0
* @since 3.12.0
*
* @param {Phaser.Loader.LoaderPlugin} loader - A reference to the Loader that is responsible for this file.
* @param {(string|Phaser.Loader.FileTypes.HTMLFileConfig)} key - The key to use for this file, or a file configuration object.
* @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `<key>.png`, i.e. if `key` was "alien" then the URL will be "alien.png".
* @param {integer} [width] - The width of the texture the HTML will be rendered to.
* @param {integer} [height] - The height of the texture the HTML will be rendered to.
* @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `<key>.txt`, i.e. if `key` was "alien" then the URL will be "alien.html".
* @param {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file.
*/
var HTMLFile = new Class({
@ -49,11 +45,8 @@ var HTMLFile = new Class({
initialize:
function HTMLFile (loader, key, url, width, height, xhrSettings)
function HTMLFile (loader, key, url, xhrSettings)
{
if (width === undefined) { width = 512; }
if (height === undefined) { height = 512; }
var extension = 'html';
if (IsPlainObject(key))
@ -64,22 +57,16 @@ var HTMLFile = new Class({
url = GetFastValue(config, 'url');
xhrSettings = GetFastValue(config, 'xhrSettings');
extension = GetFastValue(config, 'extension', extension);
width = GetFastValue(config, 'width', width);
height = GetFastValue(config, 'height', height);
}
var fileConfig = {
type: 'html',
cache: loader.textureManager,
type: 'text',
cache: loader.cacheManager.html,
extension: extension,
responseType: 'text',
key: key,
url: url,
xhrSettings: xhrSettings,
config: {
width: width,
height: height
}
xhrSettings: xhrSettings
};
File.call(this, loader, fileConfig);
@ -96,80 +83,22 @@ var HTMLFile = new Class({
{
this.state = CONST.FILE_PROCESSING;
var w = this.config.width;
var h = this.config.height;
this.data = this.xhrLoader.responseText;
var data = [];
data.push('<svg width="' + w + 'px" height="' + h + 'px" viewBox="0 0 ' + w + ' ' + h + '" xmlns="http://www.w3.org/2000/svg">');
data.push('<foreignObject width="100%" height="100%">');
data.push('<body xmlns="http://www.w3.org/1999/xhtml">');
data.push(this.xhrLoader.responseText);
data.push('</body>');
data.push('</foreignObject>');
data.push('</svg>');
var svg = [ data.join('\n') ];
var _this = this;
try
{
var blob = new window.Blob(svg, { type: 'image/svg+xml;charset=utf-8' });
}
catch (e)
{
_this.state = CONST.FILE_ERRORED;
_this.onProcessComplete();
return;
}
this.data = new Image();
this.data.crossOrigin = this.crossOrigin;
this.data.onload = function ()
{
File.revokeObjectURL(_this.data);
_this.onProcessComplete();
};
this.data.onerror = function ()
{
File.revokeObjectURL(_this.data);
_this.onProcessError();
};
File.createObjectURL(this.data, blob, 'image/svg+xml');
},
/**
* Adds this file to its target cache upon successful loading and processing.
*
* @method Phaser.Loader.FileTypes.HTMLFile#addToCache
* @since 3.7.0
*/
addToCache: function ()
{
var texture = this.cache.addImage(this.key, this.data);
this.pendingDestroy(texture);
this.onProcessComplete();
}
});
/**
* Adds an HTML File, or array of HTML Files, to the current load queue.
* Adds an HTML file, or array of HTML files, to the current load queue.
*
* You can call this method from within your Scene's `preload`, along with any other files you wish to load:
*
* ```javascript
* function preload ()
* {
* this.load.html('instructions', 'content/intro.html', 256, 512);
* this.load.html('story', files/LoginForm.html');
* }
* ```
*
@ -180,68 +109,55 @@ var HTMLFile = new Class({
* The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the
* Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been
* loaded.
*
* The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load.
* The key should be unique both in terms of files being loaded and files already present in the Texture Manager.
*
* The key must be a unique String. It is used to add the file to the global HTML Cache upon a successful load.
* The key should be unique both in terms of files being loaded and files already present in the HTML Cache.
* Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file
* then remove it from the Texture Manager first, before loading a new one.
* then remove it from the HTML Cache first, before loading a new one.
*
* Instead of passing arguments you can pass a configuration object, such as:
*
* ```javascript
* this.load.html({
* key: 'instructions',
* url: 'content/intro.html',
* width: 256,
* height: 512
* key: 'login',
* url: 'files/LoginForm.html'
* });
* ```
*
* See the documentation for `Phaser.Loader.FileTypes.HTMLFileConfig` for more details.
*
* Once the file has finished loading you can use it as a texture for a Game Object by referencing its key:
* Once the file has finished loading you can access it from its Cache using its key:
*
* ```javascript
* this.load.html('instructions', 'content/intro.html', 256, 512);
* this.load.html('login', 'files/LoginForm.html');
* // and later in your game ...
* this.add.image(x, y, 'instructions');
* var data = this.cache.html.get('login');
* ```
*
* If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files
* key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and
* this is what you would use to retrieve the image from the Texture Manager.
* key. For example, if the prefix was `LEVEL1.` and the key was `Story` the final key will be `LEVEL1.Story` and
* this is what you would use to retrieve the html from the HTML Cache.
*
* The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it.
*
* If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien"
* and no URL is given then the Loader will set the URL to be "alien.html". It will always add `.html` as the extension, although
* If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "story"
* and no URL is given then the Loader will set the URL to be "story.html". It will always add `.html` as the extension, although
* this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL.
*
* The width and height are the size of the texture to which the HTML will be rendered. It's not possible to determine these
* automatically, so you will need to provide them, either as arguments or in the file config object.
* When the HTML file has loaded a new SVG element is created with a size and viewbox set to the width and height given.
* The SVG file has a body tag added to it, with the HTML file contents included. It then calls `window.Blob` on the SVG,
* and if successful is added to the Texture Manager, otherwise it fails processing. The overall quality of the rendered
* HTML depends on your browser, and some of them may not even support the svg / blob process used. Be aware that there are
* limitations on what HTML can be inside an SVG. You can find out more details in this
* [Mozilla MDN entry](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Drawing_DOM_objects_into_a_canvas).
*
* Note: The ability to load this type of file will only be available if the Image File type has been built into Phaser.
* Note: The ability to load this type of file will only be available if the HTML File type has been built into Phaser.
* It is available in the default build but can be excluded from custom builds.
*
* @method Phaser.Loader.LoaderPlugin#html
* @fires Phaser.Loader.LoaderPlugin#addFileEvent
* @since 3.0.0
* @since 3.12.0
*
* @param {(string|Phaser.Loader.FileTypes.ImageFileConfig|Phaser.Loader.FileTypes.ImageFileConfig[])} key - The key to use for this file, or a file configuration object, or array of them.
* @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `<key>.png`, i.e. if `key` was "alien" then the URL will be "alien.png".
* @param {integer} [width=512] - The width of the texture the HTML will be rendered to.
* @param {integer} [height=512] - The height of the texture the HTML will be rendered to.
* @param {(string|Phaser.Loader.FileTypes.HTMLFileConfig|Phaser.Loader.FileTypes.HTMLFileConfig[])} key - The key to use for this file, or a file configuration object, or array of them.
* @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `<key>.html`, i.e. if `key` was "alien" then the URL will be "alien.html".
* @param {XHRSettingsObject} [xhrSettings] - An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings.
*
* @return {Phaser.Loader.LoaderPlugin} The Loader instance.
*/
FileTypesManager.register('html', function (key, url, width, height, xhrSettings)
FileTypesManager.register('html', function (key, url, xhrSettings)
{
if (Array.isArray(key))
{
@ -253,7 +169,7 @@ FileTypesManager.register('html', function (key, url, width, height, xhrSettings
}
else
{
this.addFile(new HTMLFile(this, key, url, width, height, xhrSettings));
this.addFile(new HTMLFile(this, key, url, xhrSettings));
}
return this;

View file

@ -0,0 +1,263 @@
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
var Class = require('../../utils/Class');
var CONST = require('../const');
var File = require('../File');
var FileTypesManager = require('../FileTypesManager');
var GetFastValue = require('../../utils/object/GetFastValue');
var IsPlainObject = require('../../utils/object/IsPlainObject');
/**
* @typedef {object} Phaser.Loader.FileTypes.HTMLTextureFileConfig
*
* @property {string} key - The key of the file. Must be unique within both the Loader and the Texture Manager.
* @property {string} [url] - The absolute or relative URL to load the file from.
* @property {string} [extension='html'] - The default file extension to use if no url is provided.
* @property {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file.
* @property {integer} [width=512] - The width of the texture the HTML will be rendered to.
* @property {integer} [height=512] - The height of the texture the HTML will be rendered to.
*/
/**
* @classdesc
* A single HTML File suitable for loading by the Loader.
*
* These are created when you use the Phaser.Loader.LoaderPlugin#html method and are not typically created directly.
*
* For documentation about what all the arguments and configuration options mean please see Phaser.Loader.LoaderPlugin#html.
*
* @class HTMLTextureFile
* @extends Phaser.Loader.File
* @memberOf Phaser.Loader.FileTypes
* @constructor
* @since 3.12.0
*
* @param {Phaser.Loader.LoaderPlugin} loader - A reference to the Loader that is responsible for this file.
* @param {(string|Phaser.Loader.FileTypes.HTMLTextureFileConfig)} key - The key to use for this file, or a file configuration object.
* @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `<key>.png`, i.e. if `key` was "alien" then the URL will be "alien.png".
* @param {integer} [width] - The width of the texture the HTML will be rendered to.
* @param {integer} [height] - The height of the texture the HTML will be rendered to.
* @param {XHRSettingsObject} [xhrSettings] - Extra XHR Settings specifically for this file.
*/
var HTMLTextureFile = new Class({
Extends: File,
initialize:
function HTMLTextureFile (loader, key, url, width, height, xhrSettings)
{
if (width === undefined) { width = 512; }
if (height === undefined) { height = 512; }
var extension = 'html';
if (IsPlainObject(key))
{
var config = key;
key = GetFastValue(config, 'key');
url = GetFastValue(config, 'url');
xhrSettings = GetFastValue(config, 'xhrSettings');
extension = GetFastValue(config, 'extension', extension);
width = GetFastValue(config, 'width', width);
height = GetFastValue(config, 'height', height);
}
var fileConfig = {
type: 'html',
cache: loader.textureManager,
extension: extension,
responseType: 'text',
key: key,
url: url,
xhrSettings: xhrSettings,
config: {
width: width,
height: height
}
};
File.call(this, loader, fileConfig);
},
/**
* Called automatically by Loader.nextFile.
* This method controls what extra work this File does with its loaded data.
*
* @method Phaser.Loader.FileTypes.HTMLTextureFile#onProcess
* @since 3.7.0
*/
onProcess: function ()
{
this.state = CONST.FILE_PROCESSING;
var w = this.config.width;
var h = this.config.height;
var data = [];
data.push('<svg width="' + w + 'px" height="' + h + 'px" viewBox="0 0 ' + w + ' ' + h + '" xmlns="http://www.w3.org/2000/svg">');
data.push('<foreignObject width="100%" height="100%">');
data.push('<body xmlns="http://www.w3.org/1999/xhtml">');
data.push(this.xhrLoader.responseText);
data.push('</body>');
data.push('</foreignObject>');
data.push('</svg>');
var svg = [ data.join('\n') ];
var _this = this;
try
{
var blob = new window.Blob(svg, { type: 'image/svg+xml;charset=utf-8' });
}
catch (e)
{
_this.state = CONST.FILE_ERRORED;
_this.onProcessComplete();
return;
}
this.data = new Image();
this.data.crossOrigin = this.crossOrigin;
this.data.onload = function ()
{
File.revokeObjectURL(_this.data);
_this.onProcessComplete();
};
this.data.onerror = function ()
{
File.revokeObjectURL(_this.data);
_this.onProcessError();
};
File.createObjectURL(this.data, blob, 'image/svg+xml');
},
/**
* Adds this file to its target cache upon successful loading and processing.
*
* @method Phaser.Loader.FileTypes.HTMLTextureFile#addToCache
* @since 3.7.0
*/
addToCache: function ()
{
var texture = this.cache.addImage(this.key, this.data);
this.pendingDestroy(texture);
}
});
/**
* Adds an HTML File, or array of HTML Files, to the current load queue. When the files are loaded they
* will be rendered to textures and stored in the Texture Manager.
*
* You can call this method from within your Scene's `preload`, along with any other files you wish to load:
*
* ```javascript
* function preload ()
* {
* this.load.htmlTexture('instructions', 'content/intro.html', 256, 512);
* }
* ```
*
* The file is **not** loaded right away. It is added to a queue ready to be loaded either when the loader starts,
* or if it's already running, when the next free load slot becomes available. This happens automatically if you
* are calling this from within the Scene's `preload` method, or a related callback. Because the file is queued
* it means you cannot use the file immediately after calling this method, but must wait for the file to complete.
* The typical flow for a Phaser Scene is that you load assets in the Scene's `preload` method and then when the
* Scene's `create` method is called you are guaranteed that all of those assets are ready for use and have been
* loaded.
*
* The key must be a unique String. It is used to add the file to the global Texture Manager upon a successful load.
* The key should be unique both in terms of files being loaded and files already present in the Texture Manager.
* Loading a file using a key that is already taken will result in a warning. If you wish to replace an existing file
* then remove it from the Texture Manager first, before loading a new one.
*
* Instead of passing arguments you can pass a configuration object, such as:
*
* ```javascript
* this.load.htmlTexture({
* key: 'instructions',
* url: 'content/intro.html',
* width: 256,
* height: 512
* });
* ```
*
* See the documentation for `Phaser.Loader.FileTypes.HTMLTextureFileConfig` for more details.
*
* Once the file has finished loading you can use it as a texture for a Game Object by referencing its key:
*
* ```javascript
* this.load.htmlTexture('instructions', 'content/intro.html', 256, 512);
* // and later in your game ...
* this.add.image(x, y, 'instructions');
* ```
*
* If you have specified a prefix in the loader, via `Loader.setPrefix` then this value will be prepended to this files
* key. For example, if the prefix was `MENU.` and the key was `Background` the final key will be `MENU.Background` and
* this is what you would use to retrieve the image from the Texture Manager.
*
* The URL can be relative or absolute. If the URL is relative the `Loader.baseURL` and `Loader.path` values will be prepended to it.
*
* If the URL isn't specified the Loader will take the key and create a filename from that. For example if the key is "alien"
* and no URL is given then the Loader will set the URL to be "alien.html". It will always add `.html` as the extension, although
* this can be overridden if using an object instead of method arguments. If you do not desire this action then provide a URL.
*
* The width and height are the size of the texture to which the HTML will be rendered. It's not possible to determine these
* automatically, so you will need to provide them, either as arguments or in the file config object.
* When the HTML file has loaded a new SVG element is created with a size and viewbox set to the width and height given.
* The SVG file has a body tag added to it, with the HTML file contents included. It then calls `window.Blob` on the SVG,
* and if successful is added to the Texture Manager, otherwise it fails processing. The overall quality of the rendered
* HTML depends on your browser, and some of them may not even support the svg / blob process used. Be aware that there are
* limitations on what HTML can be inside an SVG. You can find out more details in this
* [Mozilla MDN entry](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Drawing_DOM_objects_into_a_canvas).
*
* Note: The ability to load this type of file will only be available if the Image File type has been built into Phaser.
* It is available in the default build but can be excluded from custom builds.
*
* @method Phaser.Loader.LoaderPlugin#htmlTexture
* @fires Phaser.Loader.LoaderPlugin#addFileEvent
* @since 3.12.0
*
* @param {(string|Phaser.Loader.FileTypes.ImageFileConfig|Phaser.Loader.FileTypes.ImageFileConfig[])} key - The key to use for this file, or a file configuration object, or array of them.
* @param {string} [url] - The absolute or relative URL to load this file from. If undefined or `null` it will be set to `<key>.png`, i.e. if `key` was "alien" then the URL will be "alien.png".
* @param {integer} [width=512] - The width of the texture the HTML will be rendered to.
* @param {integer} [height=512] - The height of the texture the HTML will be rendered to.
* @param {XHRSettingsObject} [xhrSettings] - An XHR Settings configuration object. Used in replacement of the Loaders default XHR Settings.
*
* @return {Phaser.Loader.LoaderPlugin} The Loader instance.
*/
FileTypesManager.register('htmlTexture', function (key, url, width, height, xhrSettings)
{
if (Array.isArray(key))
{
for (var i = 0; i < key.length; i++)
{
// If it's an array it has to be an array of Objects, so we get everything out of the 'key' object
this.addFile(new HTMLTextureFile(this, key[i]));
}
}
else
{
this.addFile(new HTMLTextureFile(this, key, url, width, height, xhrSettings));
}
return this;
});
module.exports = HTMLTextureFile;

View file

@ -129,7 +129,7 @@ var TextFile = new Class({
* Once the file has finished loading you can access it from its Cache using its key:
*
* ```javascript
* this.load.image('story', 'files/IntroStory.txt');
* this.load.text('story', 'files/IntroStory.txt');
* // and later in your game ...
* var data = this.cache.text.get('story');
* ```

View file

@ -20,6 +20,7 @@ module.exports = {
GLSLFile: require('./GLSLFile'),
HTML5AudioFile: require('./HTML5AudioFile'),
HTMLFile: require('./HTMLFile'),
HTMLTextureFile: require('./HTMLTextureFile'),
ImageFile: require('./ImageFile'),
JSONFile: require('./JSONFile'),
MultiAtlasFile: require('./MultiAtlasFile'),

View file

@ -1,42 +0,0 @@
/**
* A polyfill for Function.prototype.bind
*/
if (!Function.prototype.bind) {
/* jshint freeze: false */
Function.prototype.bind = (function () {
var slice = Array.prototype.slice;
return function (thisArg) {
var target = this, boundArgs = slice.call(arguments, 1);
if (typeof target !== 'function')
{
throw new TypeError();
}
function bound() {
var args = boundArgs.concat(slice.call(arguments));
target.apply(this instanceof bound ? this : thisArg, args);
}
bound.prototype = (function F(proto) {
if (proto)
{
F.prototype = proto;
}
if (!(this instanceof F))
{
/* jshint supernew: true */
return new F;
}
})(target.prototype);
return bound;
};
})();
}

View file

@ -2,7 +2,6 @@ require('./Array.forEach');
require('./Array.isArray');
require('./AudioContextMonkeyPatch');
require('./console');
require('./Function.bind');
require('./Math.trunc');
require('./performance.now');
require('./requestAnimationFrame');

View file

@ -380,10 +380,16 @@ var CanvasRenderer = new Class({
*/
render: function (scene, children, interpolationPercentage, camera)
{
var ctx = scene.sys.context;
var scissor = (camera.x !== 0 || camera.y !== 0 || camera.width !== ctx.canvas.width || camera.height !== ctx.canvas.height);
var list = children.list;
var resolution = this.config.resolution;
var childCount = list.length;
var cx = camera._cx;
var cy = camera._cy;
var cw = camera._cw;
var ch = camera._ch;
var ctx = scene.sys.context;
var scissor = (cx !== 0 || cy !== 0 || cw !== ctx.canvas.width || ch !== ctx.canvas.height);
this.currentContext = ctx;
@ -392,7 +398,7 @@ var CanvasRenderer = new Class({
if (!camera.transparent)
{
ctx.fillStyle = camera.backgroundColor.rgba;
ctx.fillRect(camera.x, camera.y, camera.width, camera.height);
ctx.fillRect(cx, cy, cw, ch);
}
ctx.globalAlpha = camera.alpha;
@ -413,7 +419,7 @@ var CanvasRenderer = new Class({
{
ctx.save();
ctx.beginPath();
ctx.rect(camera.x * resolution, camera.y * resolution, camera.width * resolution, camera.height * resolution);
ctx.rect(cx, cy, cw, ch);
ctx.clip();
}
@ -421,9 +427,14 @@ var CanvasRenderer = new Class({
ctx.setTransform(matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]);
for (var c = 0; c < list.length; c++)
for (var i = 0; i < childCount; i++)
{
var child = list[c];
var child = list[i];
if (!child.willRender(camera))
{
continue;
}
if (child.mask)
{

View file

@ -1468,12 +1468,10 @@ var WebGLRenderer = new Class({
*/
preRenderCamera: function (camera)
{
var resolution = this.config.resolution;
var cx = Math.floor(camera.x * resolution);
var cy = Math.floor(camera.y * resolution);
var cw = Math.floor(camera.width * resolution);
var ch = Math.floor(camera.height * resolution);
var cx = camera._cx;
var cy = camera._cy;
var cw = camera._cw;
var ch = camera._ch;
this.pushScissor(cx, cy, cw, ch);
@ -1484,7 +1482,7 @@ var WebGLRenderer = new Class({
FlatTintPipeline.batchFillRect(
0, 0, 1, 1, 0,
camera.x, camera.y, camera.width, camera.height,
cx, cy, cw, ch,
Utils.getTintFromFloats(color.redGL, color.greenGL, color.blueGL, 1.0),
color.alphaGL,
1, 0, 0, 1, 0, 0,
@ -1576,11 +1574,11 @@ var WebGLRenderer = new Class({
// Apply scissor for cam region + render background color, if not transparent
this.preRenderCamera(camera);
for (var index = 0; index < childCount; ++index)
for (var i = 0; i < childCount; i++)
{
var child = list[index];
var child = list[i];
if (!child.willRender())
if (!child.willRender(camera))
{
continue;
}

View file

@ -26,45 +26,55 @@ var CullTiles = function (layer, camera, outputArray)
if (outputArray === undefined) { outputArray = []; }
outputArray.length = 0;
var tilemapLayer = layer.tilemapLayer;
var skipCull = tilemapLayer.skipCull;
var tileW = Math.floor(layer.tileWidth * tilemapLayer.scaleX);
var tileH = Math.floor(layer.tileHeight * tilemapLayer.scaleY);
var y = 0;
var x = 0;
var tile = null;
var tilemapLayer = layer.tilemapLayer;
var mapData = layer.data;
var mapWidth = layer.width;
var mapHeight = layer.height;
// Camera world view bounds, snapped for tile size
var tileW = Math.floor(layer.tileWidth * tilemapLayer.scaleX);
var tileH = Math.floor(layer.tileHeight * tilemapLayer.scaleY);
// Camera world view bounds, snapped for scaled tile size
var boundsLeft = SnapFloor(camera.worldView.x, tileW) - (tilemapLayer.cullPaddingX * tileW);
var boundsRight = SnapCeil(camera.worldView.right, tileW) + (tilemapLayer.cullPaddingX * tileW);
var boundsTop = SnapFloor(camera.worldView.y, tileH) - (tilemapLayer.cullPaddingY * tileH);
var boundsBottom = SnapCeil(camera.worldView.bottom, tileH) + (tilemapLayer.cullPaddingY * tileH);
for (var y = 0; y < mapHeight; y++)
var drawLeft = 0;
var drawRight = mapWidth;
var drawTop = 0;
var drawBottom = mapHeight;
if (!tilemapLayer.skipCull)
{
for (var x = 0; x < mapWidth; x++)
drawLeft = Math.max(0, boundsLeft / tileW);
drawRight = Math.min(mapWidth, boundsRight / tileW);
drawTop = Math.max(0, boundsTop / tileH);
drawBottom = Math.min(mapHeight, boundsBottom / tileH);
}
for (y = drawTop; y < drawBottom; y++)
{
for (x = drawLeft; x < drawRight; x++)
{
var tile = mapData[y][x];
tile = mapData[y][x];
if (!tile || tile.index === -1 || !tile.visible || tile.alpha === 0)
{
continue;
}
var tilePixelX = (tile.pixelX + tilemapLayer.x) * tilemapLayer.scaleX;
var tilePixelY = (tile.pixelY + tilemapLayer.y) * tilemapLayer.scaleY;
if (skipCull || (tilePixelX >= boundsLeft && tilePixelX + tileW <= boundsRight && tilePixelY >= boundsTop && tilePixelY + tileH <= boundsBottom))
{
outputArray.push(tile);
}
outputArray.push(tile);
}
}
tilemapLayer.tilesDrawn = outputArray.length;
tilemapLayer.tilesTotal = mapWidth * mapHeight;