phaser/src/geom/line/SetToAngle.js

35 lines
960 B
JavaScript
Raw Normal View History

2018-02-12 16:01:20 +00:00
/**
* @author Richard Davey <rich@photonstorm.com>
2019-01-15 16:20:22 +00:00
* @copyright 2019 Photon Storm Ltd.
2018-02-12 16:01:20 +00:00
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
2017-10-13 13:11:54 +00:00
/**
* Set a line to a given position, angle and length.
2017-10-13 13:11:54 +00:00
*
* @function Phaser.Geom.Line.SetToAngle
* @since 3.0.0
*
2018-03-27 13:27:08 +00:00
* @generic {Phaser.Geom.Line} O - [line,$return]
*
* @param {Phaser.Geom.Line} line - The line to set.
* @param {number} x - The horizontal start position of the line.
* @param {number} y - The vertical start position of the line.
* @param {number} angle - The angle of the line in radians.
* @param {number} length - The length of the line.
2017-10-13 13:11:54 +00:00
*
* @return {Phaser.Geom.Line} The updated line.
2017-10-13 13:11:54 +00:00
*/
var SetToAngle = function (line, x, y, angle, length)
{
line.x1 = x;
line.y1 = y;
line.x2 = x + (Math.cos(angle) * length);
line.y2 = y + (Math.sin(angle) * length);
return line;
};
module.exports = SetToAngle;