From 9eb723cfc2edb7da08dec862938985daa63038f3 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Wed, 2 Aug 2017 01:24:54 +0100 Subject: [PATCH] Added PlaceOnEllipse action and added to Group --- v3/src/actions/PlaceOnEllipse.js | 23 +++++++++++++++++++++++ v3/src/actions/index.js | 1 + v3/src/checksum.js | 2 +- v3/src/gameobjects/group/Group.js | 7 +++++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 v3/src/actions/PlaceOnEllipse.js diff --git a/v3/src/actions/PlaceOnEllipse.js b/v3/src/actions/PlaceOnEllipse.js new file mode 100644 index 000000000..0962af46c --- /dev/null +++ b/v3/src/actions/PlaceOnEllipse.js @@ -0,0 +1,23 @@ +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; diff --git a/v3/src/actions/index.js b/v3/src/actions/index.js index 4919d270e..c6ed635f5 100644 --- a/v3/src/actions/index.js +++ b/v3/src/actions/index.js @@ -11,6 +11,7 @@ module.exports = { IncXY: require('./IncXY'), IncY: require('./IncY'), PlaceOnCircle: require('./PlaceOnCircle'), + PlaceOnEllipse: require('./PlaceOnEllipse'), PlaceOnLine: require('./PlaceOnLine'), PlaceOnRectangle: require('./PlaceOnRectangle'), PlaceOnTriangle: require('./PlaceOnTriangle'), diff --git a/v3/src/checksum.js b/v3/src/checksum.js index 04674cfe8..8fd938cbb 100644 --- a/v3/src/checksum.js +++ b/v3/src/checksum.js @@ -1,4 +1,4 @@ var CHECKSUM = { -build: '5d97e130-7716-11e7-8b1c-25a8a89333fb' +build: '9aad2b50-7718-11e7-a802-eddafadf9983' }; module.exports = CHECKSUM; \ No newline at end of file diff --git a/v3/src/gameobjects/group/Group.js b/v3/src/gameobjects/group/Group.js index 0e6ab3226..a124d84c2 100644 --- a/v3/src/gameobjects/group/Group.js +++ b/v3/src/gameobjects/group/Group.js @@ -284,6 +284,13 @@ var Group = new Class({ return this; }, + placeOnEllipse: function (ellipse, startAngle, endAngle) + { + Actions.PlaceOnEllipse(this.children.entries, ellipse, startAngle, endAngle); + + return this; + }, + placeOnLine: function (line) { Actions.PlaceOnLine(this.children.entries, line);