mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 23:20:59 +00:00
Geom.Polygon.Translate
is a new function that allows you to translate all the points of a polygon by the given values.
This commit is contained in:
parent
4c6458b500
commit
ce9c750175
2 changed files with 35 additions and 0 deletions
34
src/geom/polygon/Translate.js
Normal file
34
src/geom/polygon/Translate.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2020 Photon Storm Ltd.
|
||||
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tranlates the points of the given Polygon.
|
||||
*
|
||||
* @function Phaser.Geom.Polygon.Translate
|
||||
* @since 3.25.0
|
||||
*
|
||||
* @generic {Phaser.Geom.Polygon} O - [polygon,$return]
|
||||
*
|
||||
* @param {Phaser.Geom.Polygon} polygon - The Polygon to modify.
|
||||
* @param {number} x - The amount to horizontally translate the points by.
|
||||
* @param {number} y - The amount to vertically translate the points by.
|
||||
*
|
||||
* @return {Phaser.Geom.Polygon} The modified Polygon.
|
||||
*/
|
||||
var Translate = function (polygon, x, y)
|
||||
{
|
||||
var points = polygon.points;
|
||||
|
||||
for (var i = 0; i < points.length; i++)
|
||||
{
|
||||
points[i].x += x;
|
||||
points[i].y += y;
|
||||
}
|
||||
|
||||
return polygon;
|
||||
};
|
||||
|
||||
module.exports = Translate;
|
|
@ -15,5 +15,6 @@ Polygon.GetPoints = require('./GetPoints');
|
|||
Polygon.Perimeter = require('./Perimeter');
|
||||
Polygon.Reverse = require('./Reverse');
|
||||
Polygon.Smooth = require('./Smooth');
|
||||
Polygon.Translate = require('./Translate');
|
||||
|
||||
module.exports = Polygon;
|
||||
|
|
Loading…
Reference in a new issue