|
18 | 18 | * @param {string|Phaser.RenderTexture|Phaser.BitmapData|PIXI.Texture} key - This is the image or texture used by the Rope during rendering. It can be a string which is a reference to the Cache entry, or an instance of a RenderTexture or PIXI.Texture. |
19 | 19 | * @param {string|number} frame - If this Rope is using part of a sprite sheet or texture atlas you can specify the exact frame to use by giving a string or numeric index. |
20 | 20 | */ |
21 | | -Phaser.Rope = function (game, x, y, key, frame) { |
| 21 | +Phaser.Rope = function (game, x, y, key, frame, points) { |
22 | 22 |
|
23 | 23 | this.points = []; |
24 | | - this.count = 0; |
25 | | - var length = 918/20; |
26 | | - for (var i = 0; i < 20; i++) { |
27 | | - this.points.push(new Phaser.Point(i * length, 0)); |
28 | | - } |
29 | | - console.log('points:', this.points); |
| 24 | + this.points = points; |
| 25 | + this._hasUpdateAnimation = false; |
| 26 | + this._updateAnimationCallback = null; |
30 | 27 | x = x || 0; |
31 | 28 | y = y || 0; |
32 | 29 | key = key || null; |
@@ -266,13 +263,8 @@ Phaser.Rope.prototype.preUpdate = function() { |
266 | 263 | * @memberof Phaser.Rope |
267 | 264 | */ |
268 | 265 | Phaser.Rope.prototype.update = function() { |
269 | | - |
270 | | - this.count += 0.1; |
271 | | - for (var i = 0; i < this.points.length; i++) { |
272 | | - |
273 | | - this.points[i].y = Math.sin(i * 0.5 + this.count) * 20; |
274 | | - //this.points[i].x = i * length + Math.cos(i *0.3 + this.count) * 20; |
275 | | - |
| 266 | + if(this._hasUpdateAnimation) { |
| 267 | + this.updateAnimation.call(this); |
276 | 268 | } |
277 | 269 |
|
278 | 270 | }; |
@@ -303,20 +295,6 @@ Phaser.Rope.prototype.postUpdate = function() { |
303 | 295 | } |
304 | 296 | }; |
305 | 297 |
|
306 | | -/** |
307 | | -* Sets this Rope to automatically scroll in the given direction until stopped via Rope.stopScroll(). |
308 | | -* The scroll speed is specified in pixels per second. |
309 | | -* A negative x value will scroll to the left. A positive x value will scroll to the right. |
310 | | -* A negative y value will scroll up. A positive y value will scroll down. |
311 | | -* |
312 | | -* @method Phaser.Rope#autoScroll |
313 | | -* @memberof Phaser.Rope |
314 | | -*/ |
315 | | -Phaser.Rope.prototype.autoScroll = function(x, y) { |
316 | | - |
317 | | - this._scroll.set(x, y); |
318 | | - |
319 | | -}; |
320 | 298 |
|
321 | 299 |
|
322 | 300 |
|
@@ -603,7 +581,7 @@ Object.defineProperty(Phaser.Rope.prototype, "frameName", { |
603 | 581 | }); |
604 | 582 |
|
605 | 583 | /** |
606 | | -* An Rope that is fixed to the camera uses its x/y coordinates as offsets from the top left of the camera. These are stored in Rope.cameraOffset. |
| 584 | +* A Rope that is fixed to the camera uses its x/y coordinates as offsets from the top left of the camera. These are stored in Rope.cameraOffset. |
607 | 585 | * Note that the cameraOffset values are in addition to any parent in the display list. |
608 | 586 | * So if this Rope was in a Group that has x: 200, then this will be added to the cameraOffset.x |
609 | 587 | * |
@@ -775,6 +753,60 @@ Object.defineProperty(Phaser.Rope.prototype, "y", { |
775 | 753 |
|
776 | 754 | }); |
777 | 755 |
|
| 756 | +/** |
| 757 | +* A Rope will call it's updateAnimation function on each update loop if it has one |
| 758 | +* |
| 759 | +* @name Phaser.Rope#updateAnimation |
| 760 | +* @property {function} updateAnimation - Set to a function if you'd like the rope to animate during the update phase. Set to false or null to remove it. |
| 761 | +*/ |
| 762 | +Object.defineProperty(Phaser.Rope.prototype, "updateAnimation", { |
| 763 | + |
| 764 | + get: function () { |
| 765 | + |
| 766 | + return this._updateAnimation; |
| 767 | + |
| 768 | + }, |
| 769 | + |
| 770 | + set: function (value) { |
| 771 | + if(value && typeof value === 'function') { |
| 772 | + this._hasUpdateAnimation = true; |
| 773 | + this._updateAnimation = value; |
| 774 | + } else { |
| 775 | + this._hasUpdateAnimation = false; |
| 776 | + this._updateAnimation = null; |
| 777 | + } |
| 778 | + |
| 779 | + } |
| 780 | + |
| 781 | +}); |
| 782 | + |
| 783 | +/** |
| 784 | +* The segments that make up the rope body as an array of Phaser.Rectangles |
| 785 | +* |
| 786 | +* @name Phaser.Rope#segments |
| 787 | +* @property {array} updateAnimation - Returns an array of Phaser.Rectangles that represent the segments of the given rope |
| 788 | +*/ |
| 789 | +Object.defineProperty(Phaser.Rope.prototype, "segments", { |
| 790 | + get: function() { |
| 791 | + var segments = []; |
| 792 | + var index, x1, y1, x2, y2, width, height, rect; |
| 793 | + for(var i = 0; i < this.points.length; i++) { |
| 794 | + index = i * 4; |
| 795 | + x1 = this.verticies[index]; |
| 796 | + y1 = this.verticies[index + 1]; |
| 797 | + x2 = this.verticies[index + 4]; |
| 798 | + y2 = this.verticies[index + 3]; |
| 799 | + width = Phaser.Math.difference(x1,x2); |
| 800 | + height = Phaser.Math.difference(y1,y2); |
| 801 | + x1 += this.world.x; |
| 802 | + y1 += this.world.y; |
| 803 | + rect = new Phaser.Rectangle(x1,y1, width, height); |
| 804 | + segments.push(rect); |
| 805 | + } |
| 806 | + return segments; |
| 807 | + } |
| 808 | +}); |
| 809 | + |
778 | 810 | /** |
779 | 811 | * @name Phaser.Rope#destroyPhase |
780 | 812 | * @property {boolean} destroyPhase - True if this object is currently being destroyed. |
|
0 commit comments