PageRenderTime 68ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 2ms

/build/custom/phaser-no-libs.js

https://gitlab.com/lobsterhands/phaser
JavaScript | 16212 lines | 7143 code | 3164 blank | 5905 comment | 1359 complexity | f8926a3df663dda348ed503c0eeb39a1 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /**
  2. * @author Richard Davey <rich@photonstorm.com>
  3. * @copyright 2014 Photon Storm Ltd.
  4. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
  5. *
  6. * @overview
  7. *
  8. * Phaser - http://phaser.io
  9. *
  10. * v2.0.3 "Allorallen" - Built: Fri Apr 11 2014 13:08:30
  11. *
  12. * By Richard Davey http://www.photonstorm.com @photonstorm
  13. *
  14. * Phaser is a fun, free and fast 2D game framework for making HTML5 games
  15. * for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
  16. *
  17. * Phaser uses Pixi.js for rendering, created by Mat Groves http://matgroves.com @Doormat23
  18. * Phaser uses p2.js for full-body physics, created by Stefan Hedman https://github.com/schteppe/p2.js @schteppe
  19. * Phaser contains a port of N+ Physics, converted by Richard Davey, original by http://www.metanetsoftware.com
  20. *
  21. * Many thanks to Adam Saltsman (@ADAMATOMIC) for releasing Flixel, from which both Phaser
  22. * and my love of framework development originate.
  23. *
  24. * Follow development at http://phaser.io and on our forum
  25. *
  26. * "If you want your children to be intelligent, read them fairy tales."
  27. * "If you want them to be more intelligent, read them more fairy tales."
  28. * -- Albert Einstein
  29. */
  30. /**
  31. * @author Richard Davey <rich@photonstorm.com>
  32. * @copyright 2014 Photon Storm Ltd.
  33. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
  34. */
  35. (function(){
  36. var root = this;
  37. /* global Phaser:true */
  38. /**
  39. * @author Richard Davey <rich@photonstorm.com>
  40. * @copyright 2014 Photon Storm Ltd.
  41. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
  42. */
  43. /**
  44. * @namespace Phaser
  45. */
  46. var Phaser = Phaser || {
  47. VERSION: '<%= version %>',
  48. DEV_VERSION: '2.0.3',
  49. GAMES: [],
  50. AUTO: 0,
  51. CANVAS: 1,
  52. WEBGL: 2,
  53. HEADLESS: 3,
  54. NONE: 0,
  55. LEFT: 1,
  56. RIGHT: 2,
  57. UP: 3,
  58. DOWN: 4,
  59. SPRITE: 0,
  60. BUTTON: 1,
  61. IMAGE: 2,
  62. GRAPHICS: 3,
  63. TEXT: 4,
  64. TILESPRITE: 5,
  65. BITMAPTEXT: 6,
  66. GROUP: 7,
  67. RENDERTEXTURE: 8,
  68. TILEMAP: 9,
  69. TILEMAPLAYER: 10,
  70. EMITTER: 11,
  71. POLYGON: 12,
  72. BITMAPDATA: 13,
  73. CANVAS_FILTER: 14,
  74. WEBGL_FILTER: 15,
  75. ELLIPSE: 16,
  76. SPRITEBATCH: 17,
  77. RETROFONT: 18,
  78. // The various blend modes supported by pixi / phaser
  79. blendModes: {
  80. NORMAL:0,
  81. ADD:1,
  82. MULTIPLY:2,
  83. SCREEN:3,
  84. OVERLAY:4,
  85. DARKEN:5,
  86. LIGHTEN:6,
  87. COLOR_DODGE:7,
  88. COLOR_BURN:8,
  89. HARD_LIGHT:9,
  90. SOFT_LIGHT:10,
  91. DIFFERENCE:11,
  92. EXCLUSION:12,
  93. HUE:13,
  94. SATURATION:14,
  95. COLOR:15,
  96. LUMINOSITY:16
  97. },
  98. // The scale modes
  99. scaleModes: {
  100. DEFAULT:0,
  101. LINEAR:0,
  102. NEAREST:1
  103. }
  104. };
  105. PIXI.InteractionManager = function () {
  106. // We don't need this in Pixi, so we've removed it to save space
  107. // however the Stage object expects a reference to it, so here is a dummy entry.
  108. };
  109. /* jshint supernew: true */
  110. /**
  111. * @author Richard Davey <rich@photonstorm.com>
  112. * @copyright 2014 Photon Storm Ltd.
  113. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
  114. */
  115. /**
  116. * @class Phaser.Utils
  117. * @static
  118. */
  119. Phaser.Utils = {
  120. /**
  121. * Get a unit dimension from a string.
  122. *
  123. * @method Phaser.Utils.parseDimension
  124. * @param {string|number} size - The size to parse.
  125. * @param {number} dimension - The window dimension to check.
  126. * @return {number} The parsed dimension.
  127. */
  128. parseDimension: function (size, dimension) {
  129. var f = 0;
  130. var px = 0;
  131. if (typeof size === 'string')
  132. {
  133. // %?
  134. if (size.substr(-1) === '%')
  135. {
  136. f = parseInt(size, 10) / 100;
  137. if (dimension === 0)
  138. {
  139. px = window.innerWidth * f;
  140. }
  141. else
  142. {
  143. px = window.innerHeight * f;
  144. }
  145. }
  146. else
  147. {
  148. px = parseInt(size, 10);
  149. }
  150. }
  151. else
  152. {
  153. px = size;
  154. }
  155. return px;
  156. },
  157. /**
  158. * A standard Fisher-Yates Array shuffle implementation.
  159. * @method Phaser.Utils.shuffle
  160. * @param {array} array - The array to shuffle.
  161. * @return {array} The shuffled array.
  162. */
  163. shuffle: function (array) {
  164. for (var i = array.length - 1; i > 0; i--)
  165. {
  166. var j = Math.floor(Math.random() * (i + 1));
  167. var temp = array[i];
  168. array[i] = array[j];
  169. array[j] = temp;
  170. }
  171. return array;
  172. },
  173. /**
  174. * Javascript string pad http://www.webtoolkit.info/.
  175. * pad = the string to pad it out with (defaults to a space)
  176. * dir = 1 (left), 2 (right), 3 (both)
  177. * @method Phaser.Utils.pad
  178. * @param {string} str - The target string.
  179. * @param {number} len - The number of characters to be added.
  180. * @param {number} pad - The string to pad it out with (defaults to a space).
  181. * @param {number} [dir=3] The direction dir = 1 (left), 2 (right), 3 (both).
  182. * @return {string} The padded string
  183. */
  184. pad: function (str, len, pad, dir) {
  185. if (typeof(len) == "undefined") { var len = 0; }
  186. if (typeof(pad) == "undefined") { var pad = ' '; }
  187. if (typeof(dir) == "undefined") { var dir = 3; }
  188. var padlen = 0;
  189. if (len + 1 >= str.length)
  190. {
  191. switch (dir)
  192. {
  193. case 1:
  194. str = new Array(len + 1 - str.length).join(pad) + str;
  195. break;
  196. case 3:
  197. var right = Math.ceil((padlen = len - str.length) / 2);
  198. var left = padlen - right;
  199. str = new Array(left+1).join(pad) + str + new Array(right+1).join(pad);
  200. break;
  201. default:
  202. str = str + new Array(len + 1 - str.length).join(pad);
  203. break;
  204. }
  205. }
  206. return str;
  207. },
  208. /**
  209. * This is a slightly modified version of jQuery.isPlainObject. A plain object is an object whose internal class property is [object Object].
  210. * @method Phaser.Utils.isPlainObject
  211. * @param {object} obj - The object to inspect.
  212. * @return {boolean} - true if the object is plain, otherwise false.
  213. */
  214. isPlainObject: function (obj) {
  215. // Not plain objects:
  216. // - Any object or value whose internal [[Class]] property is not "[object Object]"
  217. // - DOM nodes
  218. // - window
  219. if (typeof(obj) !== "object" || obj.nodeType || obj === obj.window)
  220. {
  221. return false;
  222. }
  223. // Support: Firefox <20
  224. // The try/catch suppresses exceptions thrown when attempting to access
  225. // the "constructor" property of certain host objects, ie. |window.location|
  226. // https://bugzilla.mozilla.org/show_bug.cgi?id=814622
  227. try {
  228. if (obj.constructor && !({}).hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf"))
  229. {
  230. return false;
  231. }
  232. } catch (e) {
  233. return false;
  234. }
  235. // If the function hasn't returned already, we're confident that
  236. // |obj| is a plain object, created by {} or constructed with new Object
  237. return true;
  238. },
  239. /**
  240. * This is a slightly modified version of http://api.jquery.com/jQuery.extend/
  241. * @method Phaser.Utils.extend
  242. * @param {boolean} deep - Perform a deep copy?
  243. * @param {object} target - The target object to copy to.
  244. * @return {object} The extended object.
  245. */
  246. extend: function () {
  247. var options, name, src, copy, copyIsArray, clone,
  248. target = arguments[0] || {},
  249. i = 1,
  250. length = arguments.length,
  251. deep = false;
  252. // Handle a deep copy situation
  253. if (typeof target === "boolean")
  254. {
  255. deep = target;
  256. target = arguments[1] || {};
  257. // skip the boolean and the target
  258. i = 2;
  259. }
  260. // extend Phaser if only one argument is passed
  261. if (length === i)
  262. {
  263. target = this;
  264. --i;
  265. }
  266. for (; i < length; i++)
  267. {
  268. // Only deal with non-null/undefined values
  269. if ((options = arguments[i]) != null)
  270. {
  271. // Extend the base object
  272. for (name in options)
  273. {
  274. src = target[name];
  275. copy = options[name];
  276. // Prevent never-ending loop
  277. if (target === copy)
  278. {
  279. continue;
  280. }
  281. // Recurse if we're merging plain objects or arrays
  282. if (deep && copy && (Phaser.Utils.isPlainObject(copy) || (copyIsArray = Array.isArray(copy))))
  283. {
  284. if (copyIsArray)
  285. {
  286. copyIsArray = false;
  287. clone = src && Array.isArray(src) ? src : [];
  288. }
  289. else
  290. {
  291. clone = src && Phaser.Utils.isPlainObject(src) ? src : {};
  292. }
  293. // Never move original objects, clone them
  294. target[name] = Phaser.Utils.extend(deep, clone, copy);
  295. // Don't bring in undefined values
  296. }
  297. else if (copy !== undefined)
  298. {
  299. target[name] = copy;
  300. }
  301. }
  302. }
  303. }
  304. // Return the modified object
  305. return target;
  306. }
  307. };
  308. /**
  309. * A polyfill for Function.prototype.bind
  310. */
  311. if (typeof Function.prototype.bind != 'function') {
  312. /* jshint freeze: false */
  313. Function.prototype.bind = (function () {
  314. var slice = Array.prototype.slice;
  315. return function (thisArg) {
  316. var target = this, boundArgs = slice.call(arguments, 1);
  317. if (typeof target != 'function')
  318. {
  319. throw new TypeError();
  320. }
  321. function bound() {
  322. var args = boundArgs.concat(slice.call(arguments));
  323. target.apply(this instanceof bound ? this : thisArg, args);
  324. }
  325. bound.prototype = (function F(proto) {
  326. if (proto)
  327. {
  328. F.prototype = proto;
  329. }
  330. if (!(this instanceof F))
  331. {
  332. return new F;
  333. }
  334. })(target.prototype);
  335. return bound;
  336. };
  337. })();
  338. }
  339. /**
  340. * A polyfill for Array.isArray
  341. */
  342. if (!Array.isArray)
  343. {
  344. Array.isArray = function (arg)
  345. {
  346. return Object.prototype.toString.call(arg) == '[object Array]';
  347. };
  348. }
  349. /**
  350. * A polyfill for Array.forEach
  351. * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
  352. */
  353. if (!Array.prototype.forEach)
  354. {
  355. Array.prototype.forEach = function(fun /*, thisArg */)
  356. {
  357. "use strict";
  358. if (this === void 0 || this === null)
  359. {
  360. throw new TypeError();
  361. }
  362. var t = Object(this);
  363. var len = t.length >>> 0;
  364. if (typeof fun !== "function")
  365. {
  366. throw new TypeError();
  367. }
  368. var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
  369. for (var i = 0; i < len; i++)
  370. {
  371. if (i in t)
  372. {
  373. fun.call(thisArg, t[i], i, t);
  374. }
  375. }
  376. };
  377. }
  378. /**
  379. * @author Richard Davey <rich@photonstorm.com>
  380. * @copyright 2014 Photon Storm Ltd.
  381. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
  382. */
  383. /**
  384. * Creates a new Circle object with the center coordinate specified by the x and y parameters and the diameter specified by the diameter parameter. If you call this function without parameters, a circle with x, y, diameter and radius properties set to 0 is created.
  385. * @class Circle
  386. * @classdesc Phaser - Circle
  387. * @constructor
  388. * @param {number} [x=0] - The x coordinate of the center of the circle.
  389. * @param {number} [y=0] - The y coordinate of the center of the circle.
  390. * @param {number} [diameter=0] - The diameter of the circle.
  391. * @return {Phaser.Circle} This circle object
  392. */
  393. Phaser.Circle = function (x, y, diameter) {
  394. x = x || 0;
  395. y = y || 0;
  396. diameter = diameter || 0;
  397. /**
  398. * @property {number} x - The x coordinate of the center of the circle.
  399. */
  400. this.x = x;
  401. /**
  402. * @property {number} y - The y coordinate of the center of the circle.
  403. */
  404. this.y = y;
  405. /**
  406. * @property {number} _diameter - The diameter of the circle.
  407. * @private
  408. */
  409. this._diameter = diameter;
  410. if (diameter > 0)
  411. {
  412. /**
  413. * @property {number} _radius - The radius of the circle.
  414. * @private
  415. */
  416. this._radius = diameter * 0.5;
  417. }
  418. else
  419. {
  420. this._radius = 0;
  421. }
  422. };
  423. Phaser.Circle.prototype = {
  424. /**
  425. * The circumference of the circle.
  426. * @method Phaser.Circle#circumference
  427. * @return {number}
  428. */
  429. circumference: function () {
  430. return 2 * (Math.PI * this._radius);
  431. },
  432. /**
  433. * Sets the members of Circle to the specified values.
  434. * @method Phaser.Circle#setTo
  435. * @param {number} x - The x coordinate of the center of the circle.
  436. * @param {number} y - The y coordinate of the center of the circle.
  437. * @param {number} diameter - The diameter of the circle in pixels.
  438. * @return {Circle} This circle object.
  439. */
  440. setTo: function (x, y, diameter) {
  441. this.x = x;
  442. this.y = y;
  443. this._diameter = diameter;
  444. this._radius = diameter * 0.5;
  445. return this;
  446. },
  447. /**
  448. * Copies the x, y and diameter properties from any given object to this Circle.
  449. * @method Phaser.Circle#copyFrom
  450. * @param {any} source - The object to copy from.
  451. * @return {Circle} This Circle object.
  452. */
  453. copyFrom: function (source) {
  454. return this.setTo(source.x, source.y, source.diameter);
  455. },
  456. /**
  457. * Copies the x, y and diameter properties from this Circle to any given object.
  458. * @method Phaser.Circle#copyTo
  459. * @param {any} dest - The object to copy to.
  460. * @return {Object} This dest object.
  461. */
  462. copyTo: function (dest) {
  463. dest.x = this.x;
  464. dest.y = this.y;
  465. dest.diameter = this._diameter;
  466. return dest;
  467. },
  468. /**
  469. * Returns the distance from the center of the Circle object to the given object
  470. * (can be Circle, Point or anything with x/y properties)
  471. * @method Phaser.Circle#distance
  472. * @param {object} dest - The target object. Must have visible x and y properties that represent the center of the object.
  473. * @param {boolean} [round] - Round the distance to the nearest integer (default false).
  474. * @return {number} The distance between this Point object and the destination Point object.
  475. */
  476. distance: function (dest, round) {
  477. if (typeof round === "undefined") { round = false; }
  478. if (round)
  479. {
  480. return Phaser.Math.distanceRound(this.x, this.y, dest.x, dest.y);
  481. }
  482. else
  483. {
  484. return Phaser.Math.distance(this.x, this.y, dest.x, dest.y);
  485. }
  486. },
  487. /**
  488. * Returns a new Circle object with the same values for the x, y, width, and height properties as this Circle object.
  489. * @method Phaser.Circle#clone
  490. * @param {Phaser.Circle} out - Optional Circle object. If given the values will be set into the object, otherwise a brand new Circle object will be created and returned.
  491. * @return {Phaser.Circle} The cloned Circle object.
  492. */
  493. clone: function (out) {
  494. if (typeof out === "undefined")
  495. {
  496. out = new Phaser.Circle(this.x, this.y, this.diameter);
  497. }
  498. else
  499. {
  500. out.setTo(this.x, this.y, this.diameter);
  501. }
  502. return out;
  503. },
  504. /**
  505. * Return true if the given x/y coordinates are within this Circle object.
  506. * @method Phaser.Circle#contains
  507. * @param {number} x - The X value of the coordinate to test.
  508. * @param {number} y - The Y value of the coordinate to test.
  509. * @return {boolean} True if the coordinates are within this circle, otherwise false.
  510. */
  511. contains: function (x, y) {
  512. return Phaser.Circle.contains(this, x, y);
  513. },
  514. /**
  515. * Returns a Point object containing the coordinates of a point on the circumference of the Circle based on the given angle.
  516. * @method Phaser.Circle#circumferencePoint
  517. * @param {number} angle - The angle in radians (unless asDegrees is true) to return the point from.
  518. * @param {boolean} asDegrees - Is the given angle in radians (false) or degrees (true)?
  519. * @param {Phaser.Point} [out] - An optional Point object to put the result in to. If none specified a new Point object will be created.
  520. * @return {Phaser.Point} The Point object holding the result.
  521. */
  522. circumferencePoint: function (angle, asDegrees, out) {
  523. return Phaser.Circle.circumferencePoint(this, angle, asDegrees, out);
  524. },
  525. /**
  526. * Adjusts the location of the Circle object, as determined by its center coordinate, by the specified amounts.
  527. * @method Phaser.Circle#offset
  528. * @param {number} dx - Moves the x value of the Circle object by this amount.
  529. * @param {number} dy - Moves the y value of the Circle object by this amount.
  530. * @return {Circle} This Circle object.
  531. */
  532. offset: function (dx, dy) {
  533. this.x += dx;
  534. this.y += dy;
  535. return this;
  536. },
  537. /**
  538. * Adjusts the location of the Circle object using a Point object as a parameter. This method is similar to the Circle.offset() method, except that it takes a Point object as a parameter.
  539. * @method Phaser.Circle#offsetPoint
  540. * @param {Point} point A Point object to use to offset this Circle object (or any valid object with exposed x and y properties).
  541. * @return {Circle} This Circle object.
  542. */
  543. offsetPoint: function (point) {
  544. return this.offset(point.x, point.y);
  545. },
  546. /**
  547. * Returns a string representation of this object.
  548. * @method Phaser.Circle#toString
  549. * @return {string} a string representation of the instance.
  550. */
  551. toString: function () {
  552. return "[{Phaser.Circle (x=" + this.x + " y=" + this.y + " diameter=" + this.diameter + " radius=" + this.radius + ")}]";
  553. }
  554. };
  555. Phaser.Circle.prototype.constructor = Phaser.Circle;
  556. /**
  557. * The largest distance between any two points on the circle. The same as the radius * 2.
  558. * @name Phaser.Circle#diameter
  559. * @property {number} diameter - Gets or sets the diameter of the circle.
  560. */
  561. Object.defineProperty(Phaser.Circle.prototype, "diameter", {
  562. get: function () {
  563. return this._diameter;
  564. },
  565. set: function (value) {
  566. if (value > 0)
  567. {
  568. this._diameter = value;
  569. this._radius = value * 0.5;
  570. }
  571. }
  572. });
  573. /**
  574. * The length of a line extending from the center of the circle to any point on the circle itself. The same as half the diameter.
  575. * @name Phaser.Circle#radius
  576. * @property {number} radius - Gets or sets the radius of the circle.
  577. */
  578. Object.defineProperty(Phaser.Circle.prototype, "radius", {
  579. get: function () {
  580. return this._radius;
  581. },
  582. set: function (value) {
  583. if (value > 0)
  584. {
  585. this._radius = value;
  586. this._diameter = value * 2;
  587. }
  588. }
  589. });
  590. /**
  591. * The x coordinate of the leftmost point of the circle. Changing the left property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property.
  592. * @name Phaser.Circle#left
  593. * @propety {number} left - Gets or sets the value of the leftmost point of the circle.
  594. */
  595. Object.defineProperty(Phaser.Circle.prototype, "left", {
  596. get: function () {
  597. return this.x - this._radius;
  598. },
  599. set: function (value) {
  600. if (value > this.x)
  601. {
  602. this._radius = 0;
  603. this._diameter = 0;
  604. }
  605. else
  606. {
  607. this.radius = this.x - value;
  608. }
  609. }
  610. });
  611. /**
  612. * The x coordinate of the rightmost point of the circle. Changing the right property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property.
  613. * @name Phaser.Circle#right
  614. * @property {number} right - Gets or sets the value of the rightmost point of the circle.
  615. */
  616. Object.defineProperty(Phaser.Circle.prototype, "right", {
  617. get: function () {
  618. return this.x + this._radius;
  619. },
  620. set: function (value) {
  621. if (value < this.x)
  622. {
  623. this._radius = 0;
  624. this._diameter = 0;
  625. }
  626. else
  627. {
  628. this.radius = value - this.x;
  629. }
  630. }
  631. });
  632. /**
  633. * The sum of the y minus the radius property. Changing the top property of a Circle object has no effect on the x and y properties, but does change the diameter.
  634. * @name Phaser.Circle#top
  635. * @property {number} top - Gets or sets the top of the circle.
  636. */
  637. Object.defineProperty(Phaser.Circle.prototype, "top", {
  638. get: function () {
  639. return this.y - this._radius;
  640. },
  641. set: function (value) {
  642. if (value > this.y)
  643. {
  644. this._radius = 0;
  645. this._diameter = 0;
  646. }
  647. else
  648. {
  649. this.radius = this.y - value;
  650. }
  651. }
  652. });
  653. /**
  654. * The sum of the y and radius properties. Changing the bottom property of a Circle object has no effect on the x and y properties, but does change the diameter.
  655. * @name Phaser.Circle#bottom
  656. * @property {number} bottom - Gets or sets the bottom of the circle.
  657. */
  658. Object.defineProperty(Phaser.Circle.prototype, "bottom", {
  659. get: function () {
  660. return this.y + this._radius;
  661. },
  662. set: function (value) {
  663. if (value < this.y)
  664. {
  665. this._radius = 0;
  666. this._diameter = 0;
  667. }
  668. else
  669. {
  670. this.radius = value - this.y;
  671. }
  672. }
  673. });
  674. /**
  675. * The area of this Circle.
  676. * @name Phaser.Circle#area
  677. * @property {number} area - The area of this circle.
  678. * @readonly
  679. */
  680. Object.defineProperty(Phaser.Circle.prototype, "area", {
  681. get: function () {
  682. if (this._radius > 0)
  683. {
  684. return Math.PI * this._radius * this._radius;
  685. }
  686. else
  687. {
  688. return 0;
  689. }
  690. }
  691. });
  692. /**
  693. * Determines whether or not this Circle object is empty. Will return a value of true if the Circle objects diameter is less than or equal to 0; otherwise false.
  694. * If set to true it will reset all of the Circle objects properties to 0. A Circle object is empty if its diameter is less than or equal to 0.
  695. * @name Phaser.Circle#empty
  696. * @property {boolean} empty - Gets or sets the empty state of the circle.
  697. */
  698. Object.defineProperty(Phaser.Circle.prototype, "empty", {
  699. get: function () {
  700. return (this._diameter === 0);
  701. },
  702. set: function (value) {
  703. if (value === true)
  704. {
  705. this.setTo(0, 0, 0);
  706. }
  707. }
  708. });
  709. /**
  710. * Return true if the given x/y coordinates are within the Circle object.
  711. * @method Phaser.Circle.contains
  712. * @param {Phaser.Circle} a - The Circle to be checked.
  713. * @param {number} x - The X value of the coordinate to test.
  714. * @param {number} y - The Y value of the coordinate to test.
  715. * @return {boolean} True if the coordinates are within this circle, otherwise false.
  716. */
  717. Phaser.Circle.contains = function (a, x, y) {
  718. // Check if x/y are within the bounds first
  719. if (a.radius > 0 && x >= a.left && x <= a.right && y >= a.top && y <= a.bottom)
  720. {
  721. var dx = (a.x - x) * (a.x - x);
  722. var dy = (a.y - y) * (a.y - y);
  723. return (dx + dy) <= (a.radius * a.radius);
  724. }
  725. else
  726. {
  727. return false;
  728. }
  729. };
  730. /**
  731. * Determines whether the two Circle objects match. This method compares the x, y and diameter properties.
  732. * @method Phaser.Circle.equals
  733. * @param {Phaser.Circle} a - The first Circle object.
  734. * @param {Phaser.Circle} b - The second Circle object.
  735. * @return {boolean} A value of true if the object has exactly the same values for the x, y and diameter properties as this Circle object; otherwise false.
  736. */
  737. Phaser.Circle.equals = function (a, b) {
  738. return (a.x == b.x && a.y == b.y && a.diameter == b.diameter);
  739. };
  740. /**
  741. * Determines whether the two Circle objects intersect.
  742. * This method checks the radius distances between the two Circle objects to see if they intersect.
  743. * @method Phaser.Circle.intersects
  744. * @param {Phaser.Circle} a - The first Circle object.
  745. * @param {Phaser.Circle} b - The second Circle object.
  746. * @return {boolean} A value of true if the specified object intersects with this Circle object; otherwise false.
  747. */
  748. Phaser.Circle.intersects = function (a, b) {
  749. return (Phaser.Math.distance(a.x, a.y, b.x, b.y) <= (a.radius + b.radius));
  750. };
  751. /**
  752. * Returns a Point object containing the coordinates of a point on the circumference of the Circle based on the given angle.
  753. * @method Phaser.Circle.circumferencePoint
  754. * @param {Phaser.Circle} a - The first Circle object.
  755. * @param {number} angle - The angle in radians (unless asDegrees is true) to return the point from.
  756. * @param {boolean} asDegrees - Is the given angle in radians (false) or degrees (true)?
  757. * @param {Phaser.Point} [out] - An optional Point object to put the result in to. If none specified a new Point object will be created.
  758. * @return {Phaser.Point} The Point object holding the result.
  759. */
  760. Phaser.Circle.circumferencePoint = function (a, angle, asDegrees, out) {
  761. if (typeof asDegrees === "undefined") { asDegrees = false; }
  762. if (typeof out === "undefined") { out = new Phaser.Point(); }
  763. if (asDegrees === true)
  764. {
  765. angle = Phaser.Math.degToRad(angle);
  766. }
  767. out.x = a.x + a.radius * Math.cos(angle);
  768. out.y = a.y + a.radius * Math.sin(angle);
  769. return out;
  770. };
  771. /**
  772. * Checks if the given Circle and Rectangle objects intersect.
  773. * @method Phaser.Circle.intersectsRectangle
  774. * @param {Phaser.Circle} c - The Circle object to test.
  775. * @param {Phaser.Rectangle} r - The Rectangle object to test.
  776. * @return {boolean} True if the two objects intersect, otherwise false.
  777. */
  778. Phaser.Circle.intersectsRectangle = function (c, r) {
  779. var cx = Math.abs(c.x - r.x - r.halfWidth);
  780. var xDist = r.halfWidth + c.radius;
  781. if (cx > xDist)
  782. {
  783. return false;
  784. }
  785. var cy = Math.abs(c.y - r.y - r.halfHeight);
  786. var yDist = r.halfHeight + c.radius;
  787. if (cy > yDist)
  788. {
  789. return false;
  790. }
  791. if (cx <= r.halfWidth || cy <= r.halfHeight)
  792. {
  793. return true;
  794. }
  795. var xCornerDist = cx - r.halfWidth;
  796. var yCornerDist = cy - r.halfHeight;
  797. var xCornerDistSq = xCornerDist * xCornerDist;
  798. var yCornerDistSq = yCornerDist * yCornerDist;
  799. var maxCornerDistSq = c.radius * c.radius;
  800. return xCornerDistSq + yCornerDistSq <= maxCornerDistSq;
  801. };
  802. // Because PIXI uses its own Circle, we'll replace it with ours to avoid duplicating code or confusion.
  803. PIXI.Circle = Phaser.Circle;
  804. /**
  805. * @author Richard Davey <rich@photonstorm.com>
  806. * @copyright 2014 Photon Storm Ltd.
  807. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
  808. */
  809. /**
  810. * Creates a new Point. If you pass no parameters a Point is created set to (0,0).
  811. * @class Phaser.Point
  812. * @classdesc The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
  813. * @constructor
  814. * @param {number} x The horizontal position of this Point (default 0)
  815. * @param {number} y The vertical position of this Point (default 0)
  816. */
  817. Phaser.Point = function (x, y) {
  818. x = x || 0;
  819. y = y || 0;
  820. /**
  821. * @property {number} x - The x coordinate of the point.
  822. */
  823. this.x = x;
  824. /**
  825. * @property {number} y - The y coordinate of the point.
  826. */
  827. this.y = y;
  828. };
  829. Phaser.Point.prototype = {
  830. /**
  831. * Copies the x and y properties from any given object to this Point.
  832. * @method Phaser.Point#copyFrom
  833. * @param {any} source - The object to copy from.
  834. * @return {Point} This Point object.
  835. */
  836. copyFrom: function (source) {
  837. return this.setTo(source.x, source.y);
  838. },
  839. /**
  840. * Inverts the x and y values of this Point
  841. * @method Phaser.Point#invert
  842. * @return {Point} This Point object.
  843. */
  844. invert: function () {
  845. return this.setTo(this.y, this.x);
  846. },
  847. /**
  848. * Sets the x and y values of this Point object to the given coordinates.
  849. * @method Phaser.Point#setTo
  850. * @param {number} x - The horizontal position of this point.
  851. * @param {number} y - The vertical position of this point.
  852. * @return {Point} This Point object. Useful for chaining method calls.
  853. */
  854. setTo: function (x, y) {
  855. this.x = x || 0;
  856. this.y = y || ( (y !== 0) ? this.x : 0 );
  857. return this;
  858. },
  859. /**
  860. * Sets the x and y values of this Point object to the given coordinates.
  861. * @method Phaser.Point#set
  862. * @param {number} x - The horizontal position of this point.
  863. * @param {number} y - The vertical position of this point.
  864. * @return {Point} This Point object. Useful for chaining method calls.
  865. */
  866. set: function (x, y) {
  867. this.x = x || 0;
  868. this.y = y || ( (y !== 0) ? this.x : 0 );
  869. return this;
  870. },
  871. /**
  872. * Adds the given x and y values to this Point.
  873. * @method Phaser.Point#add
  874. * @param {number} x - The value to add to Point.x.
  875. * @param {number} y - The value to add to Point.y.
  876. * @return {Phaser.Point} This Point object. Useful for chaining method calls.
  877. */
  878. add: function (x, y) {
  879. this.x += x;
  880. this.y += y;
  881. return this;
  882. },
  883. /**
  884. * Subtracts the given x and y values from this Point.
  885. * @method Phaser.Point#subtract
  886. * @param {number} x - The value to subtract from Point.x.
  887. * @param {number} y - The value to subtract from Point.y.
  888. * @return {Phaser.Point} This Point object. Useful for chaining method calls.
  889. */
  890. subtract: function (x, y) {
  891. this.x -= x;
  892. this.y -= y;
  893. return this;
  894. },
  895. /**
  896. * Multiplies Point.x and Point.y by the given x and y values.
  897. * @method Phaser.Point#multiply
  898. * @param {number} x - The value to multiply Point.x by.
  899. * @param {number} y - The value to multiply Point.x by.
  900. * @return {Phaser.Point} This Point object. Useful for chaining method calls.
  901. */
  902. multiply: function (x, y) {
  903. this.x *= x;
  904. this.y *= y;
  905. return this;
  906. },
  907. /**
  908. * Divides Point.x and Point.y by the given x and y values.
  909. * @method Phaser.Point#divide
  910. * @param {number} x - The value to divide Point.x by.
  911. * @param {number} y - The value to divide Point.x by.
  912. * @return {Phaser.Point} This Point object. Useful for chaining method calls.
  913. */
  914. divide: function (x, y) {
  915. this.x /= x;
  916. this.y /= y;
  917. return this;
  918. },
  919. /**
  920. * Clamps the x value of this Point to be between the given min and max.
  921. * @method Phaser.Point#clampX
  922. * @param {number} min - The minimum value to clamp this Point to.
  923. * @param {number} max - The maximum value to clamp this Point to.
  924. * @return {Phaser.Point} This Point object.
  925. */
  926. clampX: function (min, max) {
  927. this.x = Phaser.Math.clamp(this.x, min, max);
  928. return this;
  929. },
  930. /**
  931. * Clamps the y value of this Point to be between the given min and max
  932. * @method Phaser.Point#clampY
  933. * @param {number} min - The minimum value to clamp this Point to.
  934. * @param {number} max - The maximum value to clamp this Point to.
  935. * @return {Phaser.Point} This Point object.
  936. */
  937. clampY: function (min, max) {
  938. this.y = Phaser.Math.clamp(this.y, min, max);
  939. return this;
  940. },
  941. /**
  942. * Clamps this Point object values to be between the given min and max.
  943. * @method Phaser.Point#clamp
  944. * @param {number} min - The minimum value to clamp this Point to.
  945. * @param {number} max - The maximum value to clamp this Point to.
  946. * @return {Phaser.Point} This Point object.
  947. */
  948. clamp: function (min, max) {
  949. this.x = Phaser.Math.clamp(this.x, min, max);
  950. this.y = Phaser.Math.clamp(this.y, min, max);
  951. return this;
  952. },
  953. /**
  954. * Creates a copy of the given Point.
  955. * @method Phaser.Point#clone
  956. * @param {Phaser.Point} [output] Optional Point object. If given the values will be set into this object, otherwise a brand new Point object will be created and returned.
  957. * @return {Phaser.Point} The new Point object.
  958. */
  959. clone: function (output) {
  960. if (typeof output === "undefined")
  961. {
  962. output = new Phaser.Point(this.x, this.y);
  963. }
  964. else
  965. {
  966. output.setTo(this.x, this.y);
  967. }
  968. return output;
  969. },
  970. /**
  971. * Copies the x and y properties from this Point to any given object.
  972. * @method Phaser.Point#copyTo
  973. * @param {any} dest - The object to copy to.
  974. * @return {Object} The dest object.
  975. */
  976. copyTo: function(dest) {
  977. dest.x = this.x;
  978. dest.y = this.y;
  979. return dest;
  980. },
  981. /**
  982. * Returns the distance of this Point object to the given object (can be a Circle, Point or anything with x/y properties)
  983. * @method Phaser.Point#distance
  984. * @param {object} dest - The target object. Must have visible x and y properties that represent the center of the object.
  985. * @param {boolean} [round] - Round the distance to the nearest integer (default false).
  986. * @return {number} The distance between this Point object and the destination Point object.
  987. */
  988. distance: function (dest, round) {
  989. return Phaser.Point.distance(this, dest, round);
  990. },
  991. /**
  992. * Determines whether the given objects x/y values are equal to this Point object.
  993. * @method Phaser.Point#equals
  994. * @param {Phaser.Point} a - The first object to compare.
  995. * @return {boolean} A value of true if the Points are equal, otherwise false.
  996. */
  997. equals: function (a) {
  998. return (a.x == this.x && a.y == this.y);
  999. },
  1000. /**
  1001. * Rotates this Point around the x/y coordinates given to the desired angle.
  1002. * @method Phaser.Point#rotate
  1003. * @param {number} x - The x coordinate of the anchor point
  1004. * @param {number} y - The y coordinate of the anchor point
  1005. * @param {number} angle - The angle in radians (unless asDegrees is true) to rotate the Point to.
  1006. * @param {boolean} asDegrees - Is the given rotation in radians (false) or degrees (true)?
  1007. * @param {number} [distance] - An optional distance constraint between the Point and the anchor.
  1008. * @return {Phaser.Point} The modified point object.
  1009. */
  1010. rotate: function (x, y, angle, asDegrees, distance) {
  1011. return Phaser.Point.rotate(this, x, y, angle, asDegrees, distance);
  1012. },
  1013. /**
  1014. * Calculates the length of the vector
  1015. * @method Phaser.Point#getMagnitude
  1016. * @return {number} the length of the vector
  1017. */
  1018. getMagnitude: function() {
  1019. return Math.sqrt((this.x * this.x) + (this.y * this.y));
  1020. },
  1021. /**
  1022. * Alters the length of the vector without changing the direction
  1023. * @method Phaser.Point#setMagnitude
  1024. * @param {number} magnitude the desired magnitude of the resulting vector
  1025. * @return {Phaser.Point} the modified original vector
  1026. */
  1027. setMagnitude: function(magnitude) {
  1028. return this.normalize().multiply(magnitude, magnitude);
  1029. },
  1030. /**
  1031. * Alters the vector so that its length is 1, but it retains the same direction
  1032. * @method Phaser.Point#normalize
  1033. * @return {Phaser.Point} the modified original vector
  1034. */
  1035. normalize: function() {
  1036. if(!this.isZero()) {
  1037. var m = this.getMagnitude();
  1038. this.x /= m;
  1039. this.y /= m;
  1040. }
  1041. return this;
  1042. },
  1043. /**
  1044. * Determine if this point is at 0,0
  1045. * @method Phaser.Point#isZero
  1046. * @return {boolean} True if this Point is 0,0, otherwise false
  1047. */
  1048. isZero: function() {
  1049. return (this.x === 0 && this.y === 0);
  1050. },
  1051. /**
  1052. * Returns a string representation of this object.
  1053. * @method Phaser.Point#toString
  1054. * @return {string} A string representation of the instance.
  1055. */
  1056. toString: function () {
  1057. return '[{Point (x=' + this.x + ' y=' + this.y + ')}]';
  1058. }
  1059. };
  1060. Phaser.Point.prototype.constructor = Phaser.Point;
  1061. /**
  1062. * Adds the coordinates of two points together to create a new point.
  1063. * @method Phaser.Point.add
  1064. * @param {Phaser.Point} a - The first Point object.
  1065. * @param {Phaser.Point} b - The second Point object.
  1066. * @param {Phaser.Point} [out] - Optional Point to store the value in, if not supplied a new Point object will be created.
  1067. * @return {Phaser.Point} The new Point object.
  1068. */
  1069. Phaser.Point.add = function (a, b, out) {
  1070. if (typeof out === "undefined") { out = new Phaser.Point(); }
  1071. out.x = a.x + b.x;
  1072. out.y = a.y + b.y;
  1073. return out;
  1074. };
  1075. /**
  1076. * Subtracts the coordinates of two points to create a new point.
  1077. * @method Phaser.Point.subtract
  1078. * @param {Phaser.Point} a - The first Point object.
  1079. * @param {Phaser.Point} b - The second Point object.
  1080. * @param {Phaser.Point} [out] - Optional Point to store the value in, if not supplied a new Point object will be created.
  1081. * @return {Phaser.Point} The new Point object.
  1082. */
  1083. Phaser.Point.subtract = function (a, b, out) {
  1084. if (typeof out === "undefined") { out = new Phaser.Point(); }
  1085. out.x = a.x - b.x;
  1086. out.y = a.y - b.y;
  1087. return out;
  1088. };
  1089. /**
  1090. * Multiplies the coordinates of two points to create a new point.
  1091. * @method Phaser.Point.multiply
  1092. * @param {Phaser.Point} a - The first Point object.
  1093. * @param {Phaser.Point} b - The second Point object.
  1094. * @param {Phaser.Point} [out] - Optional Point to store the value in, if not supplied a new Point object will be created.
  1095. * @return {Phaser.Point} The new Point object.
  1096. */
  1097. Phaser.Point.multiply = function (a, b, out) {
  1098. if (typeof out === "undefined") { out = new Phaser.Point(); }
  1099. out.x = a.x * b.x;
  1100. out.y = a.y * b.y;
  1101. return out;
  1102. };
  1103. /**
  1104. * Divides the coordinates of two points to create a new point.
  1105. * @method Phaser.Point.divide
  1106. * @param {Phaser.Point} a - The first Point object.
  1107. * @param {Phaser.Point} b - The second Point object.
  1108. * @param {Phaser.Point} [out] - Optional Point to store the value in, if not supplied a new Point object will be created.
  1109. * @return {Phaser.Point} The new Point object.
  1110. */
  1111. Phaser.Point.divide = function (a, b, out) {
  1112. if (typeof out === "undefined") { out = new Phaser.Point(); }
  1113. out.x = a.x / b.x;
  1114. out.y = a.y / b.y;
  1115. return out;
  1116. };
  1117. /**
  1118. * Determines whether the two given Point objects are equal. They are considered equal if they have the same x and y values.
  1119. * @method Phaser.Point.equals
  1120. * @param {Phaser.Point} a - The first Point object.
  1121. * @param {Phaser.Point} b - The second Point object.
  1122. * @return {boolean} A value of true if the Points are equal, otherwise false.
  1123. */
  1124. Phaser.Point.equals = function (a, b) {
  1125. return (a.x == b.x && a.y == b.y);
  1126. };
  1127. /**
  1128. * Returns the distance of this Point object to the given object (can be a Circle, Point or anything with x/y properties).
  1129. * @method Phaser.Point.distance
  1130. * @param {object} a - The target object. Must have visible x and y properties that represent the center of the object.
  1131. * @param {object} b - The target object. Must have visible x and y properties that represent the center of the object.
  1132. * @param {boolean} [round] - Round the distance to the nearest integer (default false).
  1133. * @return {number} The distance between this Point object and the destination Point object.
  1134. */
  1135. Phaser.Point.distance = function (a, b, round) {
  1136. if (typeof round === "undefined") { round = false; }
  1137. if (round)
  1138. {
  1139. return Phaser.Math.distanceRound(a.x, a.y, b.x, b.y);
  1140. }
  1141. else
  1142. {
  1143. return Phaser.Math.distance(a.x, a.y, b.x, b.y);
  1144. }
  1145. };
  1146. /**
  1147. * Rotates a Point around the x/y coordinates given to the desired angle.
  1148. * @method Phaser.Point.rotate
  1149. * @param {Phaser.Point} a - The Point object to rotate.
  1150. * @param {number} x - The x coordinate of the anchor point
  1151. * @param {number} y - The y coordinate of the anchor point
  1152. * @param {number} angle - The angle in radians (unless asDegrees is true) to rotate the Point to.
  1153. * @param {boolean} asDegrees - Is the given rotation in radians (false) or degrees (true)?
  1154. * @param {number} distance - An optional distance constraint between the Point and the anchor.
  1155. * @return {Phaser.Point} The modified point object.
  1156. */
  1157. Phaser.Point.rotate = function (a, x, y, angle, asDegrees, distance) {
  1158. asDegrees = asDegrees || false;
  1159. distance = distance || null;
  1160. if (asDegrees)
  1161. {
  1162. angle = Phaser.Math.degToRad(angle);
  1163. }
  1164. // Get distance from origin (cx/cy) to this point
  1165. if (distance === null)
  1166. {
  1167. distance = Math.sqrt(((x - a.x) * (x - a.x)) + ((y - a.y) * (y - a.y)));
  1168. }
  1169. return a.setTo(x + distance * Math.cos(angle), y + distance * Math.sin(angle));
  1170. };
  1171. /**
  1172. * Calculates centroid (or midpoint) from an array of points. If only one point is provided, that point is returned.
  1173. * @method Phaser.Point.centroid
  1174. * @param {Phaser.Point[]} points - The array of one or more points.
  1175. * @param {Phaser.Point} [out] - Optional Point to store the value in, if not supplied a new Point object will be created.
  1176. * @return {Phaser.Point} The new Point object.
  1177. */
  1178. Phaser.Point.centroid = function (points, out) {
  1179. if (typeof out === "undefined") { out = new Phaser.Point(); }
  1180. if (Object.prototype.toString.call(points) !== '[object Array]')
  1181. {
  1182. throw new Error("Phaser.Point. Parameter 'points' must be an array");
  1183. }
  1184. var pointslength = points.length;
  1185. if (pointslength < 1)
  1186. {
  1187. throw new Error("Phaser.Point. Parameter 'points' array must not be empty");
  1188. }
  1189. if (pointslength === 1)
  1190. {
  1191. out.copyFrom(points[0]);
  1192. return out;
  1193. }
  1194. for (var i = 0; i < pointslength; i++)
  1195. {
  1196. Phaser.Point.add(out, points[i], out);
  1197. }
  1198. out.divide(pointslength, pointslength);
  1199. return out;
  1200. };
  1201. // Because PIXI uses its own Point, we'll replace it with ours to avoid duplicating code or confusion.
  1202. PIXI.Point = Phaser.Point;
  1203. /**
  1204. * @author Richard Davey <rich@photonstorm.com>
  1205. * @copyright 2014 Photon Storm Ltd.
  1206. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
  1207. */
  1208. /**
  1209. * Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a Rectangle with x, y, width, and height properties set to 0 is created.
  1210. *
  1211. * @class Phaser.Rectangle
  1212. * @constructor
  1213. * @param {number} x - The x coordinate of the top-left corner of the Rectangle.
  1214. * @param {number} y - The y coordinate of the top-left corner of the Rectangle.
  1215. * @param {number} width - The width of the Rectangle.
  1216. * @param {number} height - The height of the Rectangle.
  1217. * @return {Phaser.Rectangle} This Rectangle object.
  1218. */
  1219. Phaser.Rectangle = function (x, y, width, height) {
  1220. x = x || 0;
  1221. y = y || 0;
  1222. width = width || 0;
  1223. height = height || 0;
  1224. /**
  1225. * @property {number} x - The x coordinate of the top-left corner of the Rectangle.
  1226. */
  1227. this.x = x;
  1228. /**
  1229. * @property {number} y - The y coordinate of the top-left corner of the Rectangle.
  1230. */
  1231. this.y = y;
  1232. /**
  1233. * @property {number} width - The width of the Rectangle.
  1234. */
  1235. this.width = width;
  1236. /**
  1237. * @property {number} height - The height of the Rectangle.
  1238. */
  1239. this.height = height;
  1240. };
  1241. Phaser.Rectangle.prototype = {
  1242. /**
  1243. * Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.
  1244. * @method Phaser.Rectangle#offset
  1245. * @param {number} dx - Moves the x value of the Rectangle object by this amount.
  1246. * @param {number} dy - Moves the y value of the Rectangle object by this amount.
  1247. * @return {Phaser.Rectangle} This Rectangle object.
  1248. */
  1249. offset: function (dx, dy) {
  1250. this.x += dx;
  1251. this.y += dy;
  1252. return this;
  1253. },
  1254. /**
  1255. * Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter.
  1256. * @method Phaser.Rectangle#offsetPoint
  1257. * @param {Phaser.Point} point - A Point object to use to offset this Rectangle object.
  1258. * @return {Phaser.Rectangle} This Rectangle object.
  1259. */
  1260. offsetPoint: function (point) {
  1261. return this.offset(point.x, point.y);
  1262. },
  1263. /**
  1264. * Sets the members of Rectangle to the specified values.
  1265. * @method Phaser.Rectangle#setTo
  1266. * @param {number} x - The x coordinate of the top-left corner of the Rectangle.
  1267. * @param {number} y - The y coordinate of the top-left corner of the Rectangle.
  1268. * @param {number} width - The width of the Rectangle in pixels.
  1269. * @param {number} height - The height of the Rectangle in pixels.
  1270. * @return {Phaser.Rectangle} This Rectangle object
  1271. */
  1272. setTo: function (x, y, width, height) {
  1273. this.x = x;
  1274. this.y = y;
  1275. this.width = width;
  1276. this.height = height;
  1277. return this;
  1278. },
  1279. /**
  1280. * Runs Math.floor() on both the x and y values of this Rectangle.
  1281. * @method Phaser.Rectangle#floor
  1282. */
  1283. floor: function () {
  1284. this.x = Math.floor(this.x);
  1285. this.y = Math.floor(this.y);
  1286. },
  1287. /**
  1288. * Runs Math.floor() on the x, y, width and height values of this Rectangle.
  1289. * @method Phaser.Rectangle#floorAll
  1290. */
  1291. floorAll: function () {
  1292. this.x = Math.floor(this.x);
  1293. this.y = Math.floor(this.y);
  1294. this.width = Math.floor(this.width);
  1295. this.height = Math.floor(this.height);
  1296. },
  1297. /**
  1298. * Copies the x, y, width and height properties from any given object to this Rectangle.
  1299. * @method Phaser.Rectangle#copyFrom
  1300. * @param {any} source - The object to copy from.
  1301. * @return {Phaser.Rectangle} This Rectangle object.
  1302. */
  1303. copyFrom: function (source) {
  1304. return this.setTo(source.x, source.y, source.width, source.height);
  1305. },
  1306. /**
  1307. * Copies the x, y, width and height properties from this Rectangle to any given object.
  1308. * @method Phaser.Rectangle#copyTo
  1309. * @param {any} source - The object to copy to.
  1310. * @return {object} This object.
  1311. */
  1312. copyTo: function (dest) {
  1313. dest.x = this.x;
  1314. dest.y = this.y;
  1315. dest.width = this.width;
  1316. dest.height = this.height;
  1317. return dest;
  1318. },
  1319. /**
  1320. * Increases the size of the Rectangle object by the specified amounts. The center point of the Rectangle object stays the same, and its size increases to the left and right by the dx value, and to the top and the bottom by the dy value.
  1321. * @method Phaser.Rectangle#inflate
  1322. * @param {number} dx - The amount to be added to the left side of the Rectangle.
  1323. * @param {number} dy - The amount to be added to the bottom side of the Rectangle.
  1324. * @return {Phaser.Rectangle} This Rectangle object.
  1325. */
  1326. inflate: function (dx, dy) {
  1327. return Phaser.Rectangle.inflate(this, dx, dy);
  1328. },
  1329. /**
  1330. * The size of the Rectangle object, expressed as a Point object with the values of the width and height properties.
  1331. * @method Phaser.Rectangle#size
  1332. * @param {Phaser.Point} [output] - Optional Point object. If given the values will be set into the object, otherwise a brand new Point object will be created and returned.
  1333. * @return {Phaser.Point} The size of the Rectangle object.
  1334. */
  1335. size: function (output) {
  1336. return Phaser.Rectangle.size(this, output);
  1337. },
  1338. /**
  1339. * Returns a new Rectangle object with the same values for the x, y, width, and height properties as the original Rectangle object.
  1340. * @method Phaser.Rectangle#clone
  1341. * @param {Phaser.Rectangle} [output] - Optional Rectangle object. If given the values will be set into the object, otherwise a brand new Rectangle object will be created and returned.
  1342. * @return {Phaser.Rectangle}
  1343. */
  1344. clone: function (output) {
  1345. return Phaser.Rectangle.clone(this, output);
  1346. },
  1347. /**
  1348. * Determines whether the specified coordinates are contained within the region defined by this Rectangle object.
  1349. * @method Phaser.Rectangle#contains
  1350. * @param {number} x - The x coordinate of the point to test.
  1351. * @param {number} y - The y coordinate of the point to test.
  1352. * @return {boolean} A value of true if the Rectangle object contains the specified point; otherwise false.
  1353. */
  1354. contains: function (x, y) {
  1355. return Phaser.Rectangle.contains(this, x, y);
  1356. },
  1357. /**
  1358. * Determines whether the first Rectangle object is fully contained within the second Rectangle object.
  1359. * A Rectangle object is said to contain another if the second Rectangle object falls entirely within the boundaries of the first.
  1360. * @method Phaser.Rectangle#containsRect
  1361. * @param {Phaser.Rectangle} b - The second Rectangle object.
  1362. * @return {boolean} …

Large files files are truncated, but you can click here to view the full file