/** * @author Richard Davey * @copyright 2019 Photon Storm Ltd. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ /** * Takes an array of Game Objects and positions them on evenly spaced points around the perimeter of an Ellipse. * * If you wish to pass a `Phaser.GameObjects.Ellipse` Shape to this function, you should pass its `geom` property. * * @function Phaser.Actions.PlaceOnEllipse * @since 3.0.0 * * @generic {Phaser.GameObjects.GameObject[]} G - [items,$return] * * @param {(array|Phaser.GameObjects.GameObject[])} items - An array of Game Objects. The contents of this array are updated by this Action. * @param {Phaser.Geom.Ellipse} ellipse - The Ellipse to position the Game Objects on. * @param {number} [startAngle=0] - Optional angle to start position from, in radians. * @param {number} [endAngle=6.28] - Optional angle to stop position at, in radians. * * @return {(array|Phaser.GameObjects.GameObject[])} The array of Game Objects that was passed to this Action. */ var PlaceOnEllipse = function (items, ellipse, startAngle, endAngle) { if (startAngle === undefined) { startAngle = 0; } if (endAngle === undefined) { endAngle = 6.28; } var angle = startAngle; var angleStep = (endAngle - startAngle) / items.length; var a = ellipse.width / 2; var b = ellipse.height / 2; for (var i = 0; i < items.length; i++) { items[i].x = ellipse.x + a * Math.cos(angle); items[i].y = ellipse.y + b * Math.sin(angle); angle += angleStep; } return items; }; module.exports = PlaceOnEllipse;