mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00:00
PlaceOnRectangle now uses MarchingAnts and has a new shift argument.
This commit is contained in:
parent
081b2816ce
commit
dccda7a5b3
3 changed files with 27 additions and 10 deletions
|
@ -1,15 +1,32 @@
|
|||
var PerimeterPoint = require('../geom/rectangle/PerimeterPoint');
|
||||
var MarchingAnts = require('../geom/rectangle/MarchingAnts');
|
||||
var RotateLeft = require('../utils/array/RotateLeft');
|
||||
var RotateRight = require('../utils/array/RotateRight');
|
||||
|
||||
var PlaceOnRectangle = function (items, rect)
|
||||
// Place the items in the array around the perimeter of the given rectangle.
|
||||
|
||||
// Placement starts from the top-left of the rectangle, and proceeds in a
|
||||
// clockwise direction. If the shift parameter is given you can offset where
|
||||
// placement begins.
|
||||
|
||||
var PlaceOnRectangle = function (items, rect, shift)
|
||||
{
|
||||
var angle = 0;
|
||||
var step = 360 / items.length;
|
||||
if (shift === undefined) { shift = 0; }
|
||||
|
||||
var points = MarchingAnts(rect, false, items.length);
|
||||
|
||||
if (shift > 0)
|
||||
{
|
||||
RotateLeft(points, shift);
|
||||
}
|
||||
else if (shift < 0)
|
||||
{
|
||||
RotateRight(points, Math.abs(shift));
|
||||
}
|
||||
|
||||
for (var i = 0; i < items.length; i++)
|
||||
{
|
||||
PerimeterPoint(rect, angle, items[i]);
|
||||
|
||||
angle += step;
|
||||
items[i].x = points[i].x;
|
||||
items[i].y = points[i].y;
|
||||
}
|
||||
|
||||
return items;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var CHECKSUM = {
|
||||
build: '2bdd4310-14b0-11e7-829e-c915fb3f8068'
|
||||
build: '237de9e0-14b5-11e7-9970-cb460f4880e6'
|
||||
};
|
||||
module.exports = CHECKSUM;
|
|
@ -231,9 +231,9 @@ var Layer = new Class({
|
|||
return this;
|
||||
},
|
||||
|
||||
placeOnRectangle: function (rect)
|
||||
placeOnRectangle: function (rect, shift)
|
||||
{
|
||||
Actions.PlaceOnRectangle(this.children.entries, rect);
|
||||
Actions.PlaceOnRectangle(this.children.entries, rect, shift);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue