Added jsdocs

This commit is contained in:
Richard Davey 2018-02-09 13:46:04 +00:00
parent ff1a26c7a3
commit b525ecb502
12 changed files with 587 additions and 40 deletions

View file

@ -1,22 +1,107 @@
var CONST = {
/**
* Phaser Release Version
*
* @name Phaser.VERSION
* @type {string}
* @since 3.0.0
*/
VERSION: '3.0.0',
BlendModes: require('./renderer/BlendModes'),
ScaleModes: require('./renderer/ScaleModes'),
/**
* AUTO Detect Renderer.
*
* @name Phaser.AUTO
* @type {integer}
* @since 3.0.0
*/
AUTO: 0,
/**
* Canvas Renderer.
*
* @name Phaser.CANVAS
* @type {integer}
* @since 3.0.0
*/
CANVAS: 1,
/**
* WebGL Renderer.
*
* @name Phaser.WEBGL
* @type {integer}
* @since 3.0.0
*/
WEBGL: 2,
/**
* Headless Renderer.
*
* @name Phaser.HEADLESS
* @type {integer}
* @since 3.0.0
*/
HEADLESS: 3,
/**
* In Phaser the value -1 means 'forever' in lots of cases, this const allows you to use it instead
* to help you remember what the value is doing in your code.
*
* @name Phaser.FOREVER
* @type {integer}
* @since 3.0.0
*/
FOREVER: -1,
/**
* Direction constant.
*
* @name Phaser.NONE
* @type {integer}
* @since 3.0.0
*/
NONE: 4,
/**
* Direction constant.
*
* @name Phaser.UP
* @type {integer}
* @since 3.0.0
*/
UP: 5,
/**
* Direction constant.
*
* @name Phaser.DOWN
* @type {integer}
* @since 3.0.0
*/
DOWN: 6,
/**
* Direction constant.
*
* @name Phaser.LEFT
* @type {integer}
* @since 3.0.0
*/
LEFT: 7,
/**
* Direction constant.
*
* @name Phaser.RIGHT
* @type {integer}
* @since 3.0.0
*/
RIGHT: 8
};

View file

@ -1,24 +1,169 @@
// Phaser.BlendModes
/**
* @namespace Phaser.BlendModes
*/
module.exports = {
/**
* Skips the Blend Mode check in the renderer.
*
* @name Phaser.BlendModes.SKIP_CHECK
* @type {integer}
* @since 3.0.0
*/
SKIP_CHECK: -1,
/**
* Normal blend mode.
*
* @name Phaser.BlendModes.NORMAL
* @type {integer}
* @since 3.0.0
*/
NORMAL: 0,
/**
* Add blend mode.
*
* @name Phaser.BlendModes.ADD
* @type {integer}
* @since 3.0.0
*/
ADD: 1,
/**
* Multiply blend mode.
*
* @name Phaser.BlendModes.MULTIPLY
* @type {integer}
* @since 3.0.0
*/
MULTIPLY: 2,
/**
* Screen blend mode.
*
* @name Phaser.BlendModes.SCREEN
* @type {integer}
* @since 3.0.0
*/
SCREEN: 3,
/**
* Overlay blend mode.
*
* @name Phaser.BlendModes.OVERLAY
* @type {integer}
* @since 3.0.0
*/
OVERLAY: 4,
/**
* Darken blend mode.
*
* @name Phaser.BlendModes.DARKEN
* @type {integer}
* @since 3.0.0
*/
DARKEN: 5,
/**
* Lighten blend mode.
*
* @name Phaser.BlendModes.LIGHTEN
* @type {integer}
* @since 3.0.0
*/
LIGHTEN: 6,
/**
* Color Dodge blend mode.
*
* @name Phaser.BlendModes.COLOR_DODGE
* @type {integer}
* @since 3.0.0
*/
COLOR_DODGE: 7,
/**
* Color Burn blend mode.
*
* @name Phaser.BlendModes.COLOR_BURN
* @type {integer}
* @since 3.0.0
*/
COLOR_BURN: 8,
/**
* Hard Light blend mode.
*
* @name Phaser.BlendModes.SOFT_LIGHT
* @type {integer}
* @since 3.0.0
*/
HARD_LIGHT: 9,
/**
* Soft Light blend mode.
*
* @name Phaser.BlendModes.SOFT_LIGHT
* @type {integer}
* @since 3.0.0
*/
SOFT_LIGHT: 10,
/**
* Difference blend mode.
*
* @name Phaser.BlendModes.DIFFERENCE
* @type {integer}
* @since 3.0.0
*/
DIFFERENCE: 11,
/**
* Exclusion blend mode.
*
* @name Phaser.BlendModes.EXCLUSION
* @type {integer}
* @since 3.0.0
*/
EXCLUSION: 12,
/**
* Hue blend mode.
*
* @name Phaser.BlendModes.HUE
* @type {integer}
* @since 3.0.0
*/
HUE: 13,
/**
* Saturation blend mode.
*
* @name Phaser.BlendModes.SATURATION
* @type {integer}
* @since 3.0.0
*/
SATURATION: 14,
/**
* Color blend mode.
*
* @name Phaser.BlendModes.COLOR
* @type {integer}
* @since 3.0.0
*/
COLOR: 15,
/**
* Luminosity blend mode.
*
* @name Phaser.BlendModes.LUMINOSITY
* @type {integer}
* @since 3.0.0
*/
LUMINOSITY: 16
};

View file

@ -1,7 +1,34 @@
/**
* @namespace Phaser.ScaleModes
*/
module.exports = {
/**
* Default Scale Mode (Linear).
*
* @name Phaser.ScaleModes.DEFAULT
* @type {integer}
* @since 3.0.0
*/
DEFAULT: 0,
/**
* Linear Scale Mode.
*
* @name Phaser.ScaleModes.LINEAR
* @type {integer}
* @since 3.0.0
*/
LINEAR: 0,
/**
* Nearest Scale Mode.
*
* @name Phaser.ScaleModes.NEAREST
* @type {integer}
* @since 3.0.0
*/
NEAREST: 1
};

View file

@ -8,9 +8,16 @@ var ScaleModes = require('../ScaleModes');
var Smoothing = require('../../display/canvas/Smoothing');
/**
* @namespace Phaser.Renderer.CanvasRenderer
* @classdesc
* [description]
*
* @class CanvasRenderer
* @memberOf Phaser.Renderer.Canvas
* @constructor
* @since 3.0.0
*
* @param {Phaser.Game} game - The Phaser Game instance that owns this renderer.
*/
var CanvasRenderer = new Class({
initialize:
@ -18,65 +25,215 @@ var CanvasRenderer = new Class({
function CanvasRenderer (game)
{
/**
* @property {Phaser.Game} game - A reference to the currently running Game.
*/
* The Phaser Game instance that owns this renderer.
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#game
* @type {[type]}
* @since 3.0.0
*/
this.game = game;
// Needed?
/**
* [description]
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#type
* @type {integer}
* @since 3.0.0
*/
this.type = CONST.CANVAS;
/**
* [description]
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#drawCount
* @type {number}
* @default 0
* @since 3.0.0
*/
this.drawCount = 0;
// Read all the following from game config (or Scene config?)
// this.clearBeforeRender = true;
// this.transparent = false;
// this.autoResize = false;
// this.roundPixels = false;
/**
* [description]
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#width
* @type {number}
* @since 3.0.0
*/
this.width = game.config.width * game.config.resolution;
/**
* [description]
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#height
* @type {number}
* @since 3.0.0
*/
this.height = game.config.height * game.config.resolution;
/**
* [description]
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#resolution
* @type {[type]}
* @since 3.0.0
*/
this.resolution = game.config.resolution;
/**
* [description]
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#scaleMode
* @type {integer}
* @since 3.0.0
*/
this.scaleMode = (game.config.pixelArt) ? ScaleModes.NEAREST : ScaleModes.LINEAR;
/**
* [description]
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#gameCanvas
* @type {HTMLCanvasElement}
* @since 3.0.0
*/
this.gameCanvas = game.canvas;
/**
* The canvas 2d context that everything is drawn with
* @property context
* @type CanvasRenderingContext2D
* [description]
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#gameContext
* @type {CanvasRenderingContext2D}
* @since 3.0.0
*/
this.gameContext = this.gameCanvas.getContext('2d');
/**
* [description]
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#gameConfig
* @type {Phaser.Boot.Config}
* @since 3.0.0
*/
this.gameConfig = game.config;
/**
* [description]
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#currentContext
* @type {CanvasRenderingContext2D}
* @since 3.0.0
*/
this.currentContext = this.gameContext;
// Map to the required function
/**
* Map to the required function.
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#drawImage
* @type {function}
* @since 3.0.0
*/
this.drawImage = DrawImage;
/**
* [description]
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#blitImage
* @type {function}
* @since 3.0.0
*/
this.blitImage = BlitImage;
/**
* [description]
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#blendModes
* @type {array}
* @since 3.0.0
*/
this.blendModes = GetBlendModes();
/**
* [description]
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#currentAlpha
* @type {number}
* @default 1
* @since 3.0.0
*/
this.currentAlpha = 1;
/**
* [description]
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#currentBlendMode
* @type {number}
* @default 0
* @since 3.0.0
*/
this.currentBlendMode = 0;
/**
* [description]
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#currentScaleMode
* @type {number}
* @default 0
* @since 3.0.0
*/
this.currentScaleMode = 0;
// this.tintMethod = this.tintWithPerPixel;
/**
* [description]
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#snapshotCallback
* @type {?function}
* @default null
* @since 3.0.0
*/
this.snapshotCallback = null;
/**
* [description]
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#snapshotType
* @type {?[type]}
* @default null
* @since 3.0.0
*/
this.snapshotType = null;
/**
* [description]
*
* @name Phaser.Renderer.Canvas.CanvasRenderer#snapshotEncoder
* @type {?[type]}
* @default null
* @since 3.0.0
*/
this.snapshotEncoder = null;
this.init();
},
/**
* [description]
*
* @method Phaser.Renderer.Canvas.CanvasRenderer#init
* @since 3.0.0
*/
init: function ()
{
this.resize(this.width, this.height);
},
// Resize the main game canvas
/**
* Resize the main game canvas.
*
* @method Phaser.Renderer.Canvas.CanvasRenderer#resize
* @since 3.0.0
*
* @param {integer} width - [description]
* @param {integer} height - [description]
*/
resize: function (width, height)
{
var res = this.game.config.resolution;
@ -100,19 +257,51 @@ var CanvasRenderer = new Class({
}
},
/**
* [description]
*
* @method Phaser.Renderer.Canvas.CanvasRenderer#onContextLost
* @since 3.0.0
*
* @param {function} callback - [description]
*/
onContextLost: function (callback)
{
},
/**
* [description]
*
* @method Phaser.Renderer.Canvas.CanvasRenderer#onContextRestored
* @since 3.0.0
*
* @param {function} callback - [description]
*/
onContextRestored: function (callback)
{
},
/**
* [description]
*
* @method Phaser.Renderer.Canvas.CanvasRenderer#resetTransform
* @since 3.0.0
*/
resetTransform: function ()
{
this.currentContext.setTransform(1, 0, 0, 1, 0, 0);
},
/**
* [description]
*
* @method Phaser.Renderer.Canvas.CanvasRenderer#setBlendMode
* @since 3.0.0
*
* @param {[type]} blendMode - [description]
*
* @return {[type]} [description]
*/
setBlendMode: function (blendMode)
{
if (this.currentBlendMode !== blendMode)
@ -124,6 +313,16 @@ var CanvasRenderer = new Class({
return this.currentBlendMode;
},
/**
* [description]
*
* @method Phaser.Renderer.Canvas.CanvasRenderer#setAlpha
* @since 3.0.0
*
* @param {float} alpha - [description]
*
* @return {float} [description]
*/
setAlpha: function (alpha)
{
if (this.currentAlpha !== alpha)
@ -135,11 +334,14 @@ var CanvasRenderer = new Class({
return this.currentAlpha;
},
// Call at the start of the render loop
/**
* Called at the start of the render loop.
*
* @method Phaser.Renderer.Canvas.CanvasRenderer#preRender
* @since 3.0.0
*/
preRender: function ()
{
// console.log('%c render start ', 'color: #ffffff; background: #00ff00;');
var ctx = this.gameContext;
var config = this.gameConfig;
@ -157,24 +359,23 @@ var CanvasRenderer = new Class({
ctx.fillRect(0, 0, width, height);
}
// Add Pre-render hook
this.drawCount = 0;
},
/**
* Renders the Scene.
* Renders the Scene to the given Camera.
*
* @method render
* @param {Phaser.Scene} scene - The Scene to be rendered.
* @param {number} interpolationPercentage - The cumulative amount of time that hasn't been simulated yet, divided
* by the amount of time that will be simulated the next time update()
* runs. Useful for interpolating frames.
* @method Phaser.Renderer.Canvas.CanvasRenderer#render
* @since 3.0.0
*
* @param {Phaser.Scene} scene - [description]
* @param {Phaser.GameObjects.DisplayList} children - [description]
* @param {float} interpolationPercentage - [description]
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
*/
render: function (scene, children, interpolationPercentage, camera)
{
var ctx = scene.sys.context;
var settings = scene.sys.settings;
var scissor = (camera.x !== 0 || camera.y !== 0 || camera.width !== ctx.canvas.width || camera.height !== ctx.canvas.height);
var list = children.list;
@ -235,9 +436,6 @@ var CanvasRenderer = new Class({
ctx.setTransform(1, 0, 0, 1, 0, 0);
// Emit a scene render event?
// scene.sys.events.emit('render', scene, ctx, camera);
if (camera._fadeAlpha > 0 || camera._flashAlpha > 0)
{
ctx.globalCompositeOperation = 'source-over';
@ -262,6 +460,12 @@ var CanvasRenderer = new Class({
}
},
/**
* [description]
*
* @method Phaser.Renderer.Canvas.CanvasRenderer#postRender
* @since 3.0.0
*/
postRender: function ()
{
var ctx = this.gameContext;
@ -279,6 +483,16 @@ var CanvasRenderer = new Class({
}
},
/**
* [description]
*
* @method Phaser.Renderer.Canvas.CanvasRenderer#snapshot
* @since 3.0.0
*
* @param {[type]} callback - [description]
* @param {[type]} type - [description]
* @param {[type]} encoderOptions - [description]
*/
snapshot: function (callback, type, encoderOptions)
{
this.snapshotCallback = callback;
@ -287,7 +501,10 @@ var CanvasRenderer = new Class({
},
/**
* @method destroy
* [description]
*
* @method Phaser.Renderer.Canvas.CanvasRenderer#destroy
* @since 3.0.0
*/
destroy: function ()
{

View file

@ -0,0 +1,12 @@
/**
* @namespace Phaser.Renderer.Canvas
*/
module.exports = {
CanvasRenderer: require('./CanvasRenderer'),
BlitImage: require('./utils/BlitImage'),
DrawImage: require('./utils/DrawImage'),
GetBlendModes: require('./utils/GetBlendModes')
};

View file

@ -1,5 +1,13 @@
// No scaling, anchor, rotation or effects, literally draws the frame directly to the canvas
/**
* No scaling, anchor, rotation or effects, literally draws the frame directly to the canvas.
*
* @function Phaser.Renderer.Canvas.BlitImage
* @since 3.0.0
*
* @param {number} dx - The x coordinate to render the Frame to.
* @param {number} dy - The y coordinate to render the Frame to.
* @param {Phaser.Textures.Frame} frame - The Frame to render.
*/
var BlitImage = function (dx, dy, frame)
{
var ctx = this.currentContext;

View file

@ -1,4 +1,12 @@
/**
* [description]
*
* @function Phaser.Renderer.Canvas.DrawImage
* @since 3.0.0
*
* @param {Phaser.GameObjects.GameObject} src - [description]
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
*/
var DrawImage = function (src, camera)
{
var ctx = this.currentContext;

View file

@ -1,6 +1,14 @@
var modes = require('../../BlendModes');
var CanvasFeatures = require('../../../device/CanvasFeatures');
/**
* [description]
*
* @function Phaser.Renderer.Canvas.GetBlendModes
* @since 3.0.0
*
* @return {array} [description]
*/
var GetBlendModes = function ()
{
var output = [];

11
src/renderer/index.js Normal file
View file

@ -0,0 +1,11 @@
/**
* @namespace Phaser.Renderer
*/
module.exports = {
Canvas: require('./canvas'),
Snapshot: require('./snapshot'),
WebGL: require('./webgl')
};

View file

@ -1,3 +1,15 @@
/**
* [description]
*
* @function Phaser.Renderer.Snapshot.Canvas
* @since 3.0.0
*
* @param {HTMLCanvasElement} canvas - [description]
* @param {string} [type='image/png'] - [description]
* @param {float} [encoderOptions=0.92] - [description]
*
* @return {Image} [description]
*/
var CanvasSnapshot = function (canvas, type, encoderOptions)
{
if (type === undefined) { type = 'image/png'; }

View file

@ -1,3 +1,15 @@
/**
* [description]
*
* @function Phaser.Renderer.Snapshot.WebGL
* @since 3.0.0
*
* @param {HTMLCanvasElement} sourceCanvas - [description]
* @param {string} [type='image/png'] - [description]
* @param {float} [encoderOptions=0.92] - [description]
*
* @return {Image} [description]
*/
var WebGLSnapshot = function (sourceCanvas, type, encoderOptions)
{
if (!type) { type = 'image/png'; }

View file

@ -1,4 +1,6 @@
// Phaser.Renderer.Snapshot
/**
* @namespace Phaser.Renderer.Snapshot
*/
module.exports = {