mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 05:03:37 +00:00
Line.centerOn will position the Line so that its midpoint lays on the coordinates given.
This commit is contained in:
parent
614b84e2ea
commit
7588e123c7
3 changed files with 17 additions and 4 deletions
|
@ -258,6 +258,7 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
|
|||
* Sprite.setTexture has a new `destroyBase` parameter - set this to `true` if you know the base used a generated texture that isn't being used by any other sprites. This will free-up the canvas for further re-use by other calls to generateTexture or Text objects.
|
||||
* Line.midPoint will return a Point object where the x and y values correspond to the center (or midpoint) of the Line segment.
|
||||
* Line.rotateAround allows you to rotate a Line around the given coordinates (in world space)
|
||||
* Line.centerOn will position the Line so that its midpoint lays on the coordinates given.
|
||||
|
||||
### Updates
|
||||
|
||||
|
|
|
@ -195,13 +195,24 @@ Phaser.Line.prototype = {
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* Centers this Line on the given coordinates.
|
||||
*
|
||||
* The line is centered by positioning the start and end points so that the lines midpoint matches
|
||||
* the coordinates given.
|
||||
*
|
||||
* @method Phaser.Line#centerOn
|
||||
* @param {number} x - The x position to center the line on.
|
||||
* @param {number} y - The y position to center the line on.
|
||||
* @return {Phaser.Line} This line object
|
||||
*/
|
||||
centerOn: function (x, y) {
|
||||
|
||||
var midx = (this.start.x + this.end.x) / 2;
|
||||
var midy = (this.start.y + this.end.y) / 2;
|
||||
var cx = (this.start.x + this.end.x) / 2;
|
||||
var cy = (this.start.y + this.end.y) / 2;
|
||||
|
||||
var tx = x - midx;
|
||||
var ty = y - midy;
|
||||
var tx = x - cx;
|
||||
var ty = y - cy;
|
||||
|
||||
this.start.add(tx, ty);
|
||||
this.end.add(tx, ty);
|
||||
|
|
1
typescript/phaser.d.ts
vendored
1
typescript/phaser.d.ts
vendored
|
@ -2125,6 +2125,7 @@ declare module Phaser {
|
|||
static intersects(a: Phaser.Line, b: Phaser.Line, asSegment?: boolean, result?: Phaser.Point): Phaser.Point;
|
||||
static reflect(a: Phaser.Line, b: Phaser.Line): number;
|
||||
|
||||
centerOn(x: number, y: number): Phaser.Line;
|
||||
clone(output: Phaser.Line): Phaser.Line;
|
||||
coordinatesOnLine(stepRate: number, results: any[]): any[];
|
||||
fromAngle(x: number, y: number, angle: number, length: number): Phaser.Line;
|
||||
|
|
Loading…
Reference in a new issue