mirror of
https://github.com/photonstorm/phaser
synced 2024-12-24 12:03:36 +00:00
29 lines
995 B
JavaScript
29 lines
995 B
JavaScript
var GetPoint = require('./GetPoint');
|
|
var FindT = require('./FindT');
|
|
|
|
/**
|
|
* Get a point on the curve using the distance, in pixels, along the curve.
|
|
*
|
|
* @param {integer} [distance=0] - The distance along the curve to get the point from, given in pixels.
|
|
* @param {Phaser.Point|Object} [point] - An optional Phaser.Point, or Object containing public `x` and `y` properties. If given the resulting values will be stored in the Objects `x` and `y` properties. If omitted a new Phaser.Point object is created.
|
|
* @return {Phaser.Point} The point on the line at the specified 'distance' along the curve.
|
|
*/
|
|
var GetPointWithDistance = function (curve, distance, out)
|
|
{
|
|
if (distance === undefined) { distance = 0; }
|
|
if (out === undefined) { out = { x: 0, y: 0 }; }
|
|
|
|
if (distance <= 0)
|
|
{
|
|
out.x = this._p1x;
|
|
out.y = this._p1y;
|
|
}
|
|
else
|
|
{
|
|
GetPoint(curve, FindT(curve, distance), out);
|
|
}
|
|
|
|
return out;
|
|
};
|
|
|
|
module.exports = GetPointWithDistance;
|