mirror of
https://github.com/wassname/phaser.git
synced 2026-07-26 13:27:43 +08:00
Adding docs.
This commit is contained in:
+52
-62
@@ -1,160 +1,145 @@
|
||||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
|
||||
* @module Phaser.Time
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is the core internal game clock. It manages the elapsed time and calculation of elapsed values,
|
||||
* used for game object motion and tweens.
|
||||
* Time constructor.
|
||||
*
|
||||
* @class Time
|
||||
* @class Phaser.Time
|
||||
* @classdesc This is the core internal game clock. It manages the elapsed time and calculation of elapsed values,
|
||||
* used for game object motion and tweens.
|
||||
* @constructor
|
||||
* @param {Phaser.Game} game A reference to the currently running game.
|
||||
*/
|
||||
Phaser.Time = function (game) {
|
||||
|
||||
/**
|
||||
* A reference to the currently running Game.
|
||||
* @property game
|
||||
* @type {Phaser.Game}
|
||||
* @property {Phaser.Game} game - Local reference to game.
|
||||
*/
|
||||
this.game = game;
|
||||
|
||||
/**
|
||||
* The time at which the Game instance started.
|
||||
* @property _started
|
||||
* @property {number} _started
|
||||
* @private
|
||||
* @type {Number}
|
||||
* @default
|
||||
*/
|
||||
this._started = 0;
|
||||
|
||||
/**
|
||||
* The time (in ms) that the last second counter ticked over.
|
||||
* @property _timeLastSecond
|
||||
* @property {number} _timeLastSecond
|
||||
* @private
|
||||
* @type {Number}
|
||||
* @default
|
||||
*/
|
||||
this._timeLastSecond = 0;
|
||||
|
||||
/**
|
||||
* The time the game started being paused.
|
||||
* @property _pauseStarted
|
||||
* @property {number} _pauseStarted
|
||||
* @private
|
||||
* @type {Number}
|
||||
* @default
|
||||
*/
|
||||
this._pauseStarted = 0;
|
||||
|
||||
/**
|
||||
* The elapsed time calculated for the physics motion updates.
|
||||
* @property physicsElapsed
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @property {number} physicsElapsed
|
||||
* @default
|
||||
*/
|
||||
this.physicsElapsed = 0;
|
||||
|
||||
/**
|
||||
* Game time counter.
|
||||
* @property time
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @property {number} time
|
||||
* @default
|
||||
*/
|
||||
this.time = 0;
|
||||
|
||||
/**
|
||||
* Records how long the game has been paused for. Is reset each time the game pauses.
|
||||
* @property pausedTime
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @property {number} pausedTime
|
||||
* @default
|
||||
*/
|
||||
this.pausedTime = 0;
|
||||
|
||||
/**
|
||||
* The time right now.
|
||||
* @property now
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @property {number} now
|
||||
* @default
|
||||
*/
|
||||
this.now = 0;
|
||||
|
||||
/**
|
||||
* Elapsed time since the last frame.
|
||||
* @property elapsed
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @property {number} elapsed
|
||||
* @default
|
||||
*/
|
||||
this.elapsed = 0;
|
||||
|
||||
/**
|
||||
* Frames per second.
|
||||
* @property fps
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @property {number} fps
|
||||
* @default
|
||||
*/
|
||||
this.fps = 0;
|
||||
|
||||
/**
|
||||
* The lowest rate the fps has dropped to.
|
||||
* @property fpsMin
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @property {number} fpsMin
|
||||
* @default
|
||||
*/
|
||||
this.fpsMin = 1000;
|
||||
|
||||
/**
|
||||
* The highest rate the fps has reached (usually no higher than 60fps).
|
||||
* @property fpsMax
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @property {number} fpsMax
|
||||
* @default
|
||||
*/
|
||||
this.fpsMax = 0;
|
||||
|
||||
/**
|
||||
* The minimum amount of time the game has taken between two frames.
|
||||
* @property msMin
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @property {number} msMin
|
||||
* @default
|
||||
*/
|
||||
this.msMin = 1000;
|
||||
|
||||
/**
|
||||
* The maximum amount of time the game has taken between two frames.
|
||||
* @property msMax
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @property {number} msMax
|
||||
* @default
|
||||
*/
|
||||
this.msMax = 0;
|
||||
|
||||
/**
|
||||
* The number of frames record in the last second.
|
||||
* @property frames
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @property {number} frames
|
||||
* @default
|
||||
*/
|
||||
this.frames = 0;
|
||||
|
||||
/**
|
||||
* Records how long the game was paused for in miliseconds.
|
||||
* @property pauseDuration
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @property {number} pauseDuration
|
||||
* @default
|
||||
*/
|
||||
this.pauseDuration = 0;
|
||||
|
||||
/**
|
||||
* The value that setTimeout needs to work out when to next update
|
||||
* @property timeToCall
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @property {number} timeToCall
|
||||
* @default
|
||||
*/
|
||||
this.timeToCall = 0;
|
||||
|
||||
/**
|
||||
* Internal value used by timeToCall as part of the setTimeout loop
|
||||
* @property lastTime
|
||||
* @public
|
||||
* @type {Number}
|
||||
* @property {number} lastTime
|
||||
* @default
|
||||
*/
|
||||
this.lastTime = 0;
|
||||
|
||||
@@ -162,6 +147,11 @@ Phaser.Time = function (game) {
|
||||
this.game.onPause.add(this.gamePaused, this);
|
||||
this.game.onResume.add(this.gameResumed, this);
|
||||
|
||||
/**
|
||||
* Description.
|
||||
* @property {bool} _justResumed
|
||||
* @default
|
||||
*/
|
||||
this._justResumed = false;
|
||||
|
||||
};
|
||||
@@ -171,7 +161,7 @@ Phaser.Time.prototype = {
|
||||
/**
|
||||
* The number of seconds that have elapsed since the game was started.
|
||||
* @method totalElapsedSeconds
|
||||
* @return {Number}
|
||||
* @return {number}
|
||||
*/
|
||||
totalElapsedSeconds: function() {
|
||||
return (this.now - this._started) * 0.001;
|
||||
@@ -179,9 +169,9 @@ Phaser.Time.prototype = {
|
||||
|
||||
/**
|
||||
* Updates the game clock and calculate the fps.
|
||||
* This is called automatically by Phaser.Game
|
||||
* This is called automatically by Phaser.Game.
|
||||
* @method update
|
||||
* @param {Number} time The current timestamp, either performance.now or Date.now depending on the browser
|
||||
* @param {number} time - The current timestamp, either performance.now or Date.now depending on the browser.
|
||||
*/
|
||||
update: function (time) {
|
||||
|
||||
@@ -251,8 +241,8 @@ Phaser.Time.prototype = {
|
||||
/**
|
||||
* How long has passed since the given time.
|
||||
* @method elapsedSince
|
||||
* @param {Number} since The time you want to measure against.
|
||||
* @return {Number} The difference between the given time and now.
|
||||
* @param {number} since - The time you want to measure against.
|
||||
* @return {number} The difference between the given time and now.
|
||||
*/
|
||||
elapsedSince: function (since) {
|
||||
return this.now - since;
|
||||
@@ -261,8 +251,8 @@ Phaser.Time.prototype = {
|
||||
/**
|
||||
* How long has passed since the given time (in seconds).
|
||||
* @method elapsedSecondsSince
|
||||
* @param {Number} since The time you want to measure (in seconds).
|
||||
* @return {Number} Duration between given time and now (in seconds).
|
||||
* @param {number} since - The time you want to measure (in seconds).
|
||||
* @return {number} Duration between given time and now (in seconds).
|
||||
*/
|
||||
elapsedSecondsSince: function (since) {
|
||||
return (this.now - since) * 0.001;
|
||||
|
||||
Reference in New Issue
Block a user