|
| 1 | +/** |
| 2 | + * @author Richard Davey <rich@photonstorm.com> |
| 3 | + * @copyright 2018 Photon Storm Ltd. |
| 4 | + * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} |
| 5 | + */ |
| 6 | + |
| 7 | +var Class = require('../../../utils/Class'); |
| 8 | +var Shape = require('../Shape'); |
| 9 | +var GeomLine = require('../../../geom/line/Line'); |
| 10 | +var LineRender = require('./LineRender'); |
| 11 | + |
| 12 | +/** |
| 13 | + * @classdesc |
| 14 | + * |
| 15 | + * @class Line |
| 16 | + * @extends Phaser.GameObjects.Shape |
| 17 | + * @memberOf Phaser.GameObjects |
| 18 | + * @constructor |
| 19 | + * @since 3.13.0 |
| 20 | + * |
| 21 | + * @param {Phaser.Scene} scene - The Scene to which this Game Object belongs. A Game Object can only belong to one Scene at a time. |
| 22 | + * @param {number} x - The horizontal position of this Game Object in the world. |
| 23 | + * @param {number} y - The vertical position of this Game Object in the world. |
| 24 | + */ |
| 25 | +var Line = new Class({ |
| 26 | + |
| 27 | + Extends: Shape, |
| 28 | + |
| 29 | + Mixins: [ |
| 30 | + LineRender |
| 31 | + ], |
| 32 | + |
| 33 | + initialize: |
| 34 | + |
| 35 | + function Line (scene, x, y, x1, y1, x2, y2, fillColor, fillAlpha) |
| 36 | + { |
| 37 | + if (x === undefined) { x = 0; } |
| 38 | + if (y === undefined) { y = 0; } |
| 39 | + if (x1 === undefined) { x1 = 0; } |
| 40 | + if (y1 === undefined) { y1 = 0; } |
| 41 | + if (x2 === undefined) { x2 = 128; } |
| 42 | + if (y2 === undefined) { y2 = 0; } |
| 43 | + |
| 44 | + Shape.call(this, scene, 'Line', new GeomLine(x1, y1, x2, y2)); |
| 45 | + |
| 46 | + var width = this.data.right - this.data.left; |
| 47 | + var height = this.data.bottom - this.data.top; |
| 48 | + |
| 49 | + this._startWidth = 1; |
| 50 | + this._endWidth = 1; |
| 51 | + |
| 52 | + this.setPosition(x, y); |
| 53 | + this.setSize(width, height); |
| 54 | + |
| 55 | + if (fillColor !== undefined) |
| 56 | + { |
| 57 | + this.setFillStyle(fillColor, fillAlpha); |
| 58 | + } |
| 59 | + |
| 60 | + this.updateDisplayOrigin(); |
| 61 | + }, |
| 62 | + |
| 63 | + setLineWidth: function (startWidth, endWidth) |
| 64 | + { |
| 65 | + if (endWidth === undefined) { endWidth = startWidth; } |
| 66 | + |
| 67 | + this._startWidth = startWidth; |
| 68 | + this._endWidth = endWidth; |
| 69 | + |
| 70 | + return this; |
| 71 | + }, |
| 72 | + |
| 73 | + /** |
| 74 | + * [description] |
| 75 | + * |
| 76 | + * @method Phaser.Geom.Line#setTo |
| 77 | + * @since 3.13.0 |
| 78 | + * |
| 79 | + * @param {number} [x1=0] - [description] |
| 80 | + * @param {number} [y1=0] - [description] |
| 81 | + * @param {number} [x2=0] - [description] |
| 82 | + * @param {number} [y2=0] - [description] |
| 83 | + * |
| 84 | + * @return {Phaser.Geom.Line} This Line object. |
| 85 | + */ |
| 86 | + setTo: function (x1, y1, x2, y2) |
| 87 | + { |
| 88 | + this.data.setTo(x1, y1, x2, y2); |
| 89 | + |
| 90 | + return this; |
| 91 | + } |
| 92 | + |
| 93 | +}); |
| 94 | + |
| 95 | +module.exports = Line; |
0 commit comments