From 562344fed0c494b310eca1a5bb66e88077fdf83e Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Thu, 29 Mar 2018 12:55:28 +0100 Subject: [PATCH] The ComputedSize Component now has `setSize` and `setDisplaySize` methods. This component is used for Game Objects that have a non-texture based size. --- CHANGELOG.md | 1 + src/gameobjects/components/ComputedSize.js | 41 +++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e78f1710a..8f5a3d46b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ being passed to the simulation. The default value is 1 to remain consistent with * BaseSound `setRate` and `setDetune` from the 3.3.0 release have moved to the WebAudioSound and HTML5AudioSound classes respectively, as they each handle the values differently. * The file `InteractiveObject.js` has been renamed to `CreateInteractiveObject.js` to more accurately reflect what it does and to avoid type errors in the docs. * Renamed the Camera Controls module exports for `Fixed` to `FixedKeyControl` and `Smoothed` to `SmoothedKeyControl` to match the class names. Fix #3463 (thanks @seivan) +* The ComputedSize Component now has `setSize` and `setDisplaySize` methods. This component is used for Game Objects that have a non-texture based size. diff --git a/src/gameobjects/components/ComputedSize.js b/src/gameobjects/components/ComputedSize.js index f8b6c749d..921badd36 100644 --- a/src/gameobjects/components/ComputedSize.js +++ b/src/gameobjects/components/ComputedSize.js @@ -5,7 +5,7 @@ */ /** - * Provides methods used for setting the blend mode of a Game Object. + * Provides methods used for calculating and setting the size of a non-Frame based Game Object. * Should be applied as a mixin and not used directly. * * @name Phaser.GameObjects.Components.ComputedSize @@ -74,6 +74,45 @@ var ComputedSize = { this.scaleY = value / this.height; } + }, + + /** + * Sets the size of this Game Object. + * + * @method Phaser.GameObjects.Components.ComputedSize#setSize + * @since 3.4.0 + * + * @param {number} width - The width of this Game Object. + * @param {number} height - The height of this Game Object. + * + * @return {Phaser.GameObjects.GameObject} This Game Object instance. + */ + setSize: function (width, height) + { + this.width = width; + this.height = height; + + return this; + }, + + /** + * Sets the display size of this Game Object. + * Calling this will adjust the scale. + * + * @method Phaser.GameObjects.Components.ComputedSize#setDisplaySize + * @since 3.4.0 + * + * @param {number} width - The width of this Game Object. + * @param {number} height - The height of this Game Object. + * + * @return {Phaser.GameObjects.GameObject} This Game Object instance. + */ + setDisplaySize: function (width, height) + { + this.displayWidth = width; + this.displayHeight = height; + + return this; } };