|
| 1 | +var Utils = require('../../renderer/webgl/Utils'); |
| 2 | + |
1 | 3 | var RenderTextureWebGL = { |
2 | 4 |
|
3 | 5 | /** |
@@ -56,41 +58,105 @@ var RenderTextureWebGL = { |
56 | 58 |
|
57 | 59 | /** |
58 | 60 | * Draws the Texture Frame to the Render Texture at the given position. |
| 61 | + * |
| 62 | + * You can either pass in a Game Object frame property: |
| 63 | + * |
| 64 | + * ```javascript |
| 65 | + * var rt = this.add.renderTexture(100, 100, 400, 300); |
| 66 | + * var bunny = this.make.sprite({ key: 'bunny' }, false); |
| 67 | + * rt.draw(bunny.frame, 0, 0); |
| 68 | + * ``` |
| 69 | + * |
| 70 | + * Or get a frame reference from the Texture Manager: |
| 71 | + * |
| 72 | + * ```javascript |
| 73 | + * var rt = this.add.renderTexture(100, 100, 400, 300); |
| 74 | + * var bunny = this.textures.getFrame('bunny'); |
| 75 | + * rt.draw(bunny, 0, 0); |
| 76 | + * ``` |
59 | 77 | * |
60 | 78 | * @method Phaser.GameObjects.RenderTexture#draw |
61 | 79 | * @since 3.2.0 |
62 | 80 | * |
63 | | - * @param {Phaser.Textures.Texture} texture - Currently unused. |
64 | | - * @param {Phaser.Textures.Frame} frame - The Texture Frame that will be drawn to the Render Texture. Get this from the Texture Manager via `this.textures.getFrame(key)`. |
| 81 | + * @param {Phaser.Textures.Frame} frame - The Texture Frame that will be drawn to the Render Texture. |
65 | 82 | * @param {number} x - The x position to draw the frame at. |
66 | 83 | * @param {number} y - The y position to draw the frame at. |
| 84 | + * @param {number} [tint] - A tint color to be applied to the frame drawn to the Render Texture. |
67 | 85 | * |
68 | | - * @return {Phaser.GameObjects.RenderTexture} This Game Object. |
| 86 | + * @return {this} This Game Object. |
69 | 87 | */ |
70 | | - draw: function (texture, frame, x, y, tint) |
| 88 | + draw: function (stamp, x, y, tint) |
71 | 89 | { |
72 | | - if (tint === undefined) |
73 | | - { |
74 | | - tint = (this.globalTint >> 16) + (this.globalTint & 0xff00) + ((this.globalTint & 0xff) << 16); |
75 | | - } |
76 | | - else |
| 90 | + if (x === undefined) { x = 0; } |
| 91 | + if (y === undefined) { y = 0; } |
| 92 | + |
| 93 | + if (!Array.isArray(stamp)) |
77 | 94 | { |
78 | | - tint = (tint >> 16) + (tint & 0xff00) + ((tint & 0xff) << 16); |
| 95 | + stamp = [ stamp ]; |
79 | 96 | } |
80 | 97 |
|
81 | 98 | this.renderer.setFramebuffer(this.framebuffer); |
82 | 99 |
|
83 | 100 | var pipeline = this.pipeline; |
84 | 101 |
|
85 | | - pipeline.projOrtho(0, pipeline.width, 0, pipeline.height, -1000.0, 1000.0); |
| 102 | + pipeline.projOrtho(0, this.width, 0, this.height, -1000.0, 1000.0); |
86 | 103 |
|
87 | | - pipeline.drawTextureFrame(frame, x, y, tint, this.globalAlpha, this.currentMatrix, null); |
| 104 | + for (var i = 0; i < stamp.length; i++) |
| 105 | + { |
| 106 | + if (stamp[i].frame) |
| 107 | + { |
| 108 | + this.drawGameObject(stamp[i], x, y); |
| 109 | + } |
| 110 | + { |
| 111 | + this.drawFrame(stamp[i], x, y, tint); |
| 112 | + } |
| 113 | + } |
| 114 | + |
| 115 | + pipeline.flush(); |
88 | 116 |
|
89 | 117 | this.renderer.setFramebuffer(null); |
90 | 118 |
|
91 | 119 | pipeline.projOrtho(0, pipeline.width, pipeline.height, 0, -1000.0, 1000.0); |
92 | 120 |
|
93 | 121 | return this; |
| 122 | + }, |
| 123 | + |
| 124 | + drawGameObject: function (gameObject, x, y) |
| 125 | + { |
| 126 | + var getTint = Utils.getTintAppendFloatAlpha; |
| 127 | + |
| 128 | + this.pipeline.batchTextureFrame( |
| 129 | + gameObject, |
| 130 | + gameObject.frame, |
| 131 | + x, y, |
| 132 | + gameObject.width, gameObject.height, |
| 133 | + gameObject.scaleX, gameObject.scaleY, |
| 134 | + gameObject.rotation, |
| 135 | + gameObject.flipX, gameObject.flipY, |
| 136 | + gameObject.displayOriginX, gameObject.displayOriginY, |
| 137 | + getTint(gameObject._tintTL, this.alpha * gameObject._alphaTL), |
| 138 | + getTint(gameObject._tintTR, this.alpha * gameObject._alphaTR), |
| 139 | + getTint(gameObject._tintBL, this.alpha * gameObject._alphaBL), |
| 140 | + getTint(gameObject._tintBR, this.alpha * gameObject._alphaBR), |
| 141 | + (gameObject._isTinted && gameObject.tintFill), |
| 142 | + null |
| 143 | + ); |
| 144 | + }, |
| 145 | + |
| 146 | + drawFrame: function (frame, x, y, tint) |
| 147 | + { |
| 148 | + if (tint === undefined) |
| 149 | + { |
| 150 | + tint = (this.globalTint >> 16) + (this.globalTint & 0xff00) + ((this.globalTint & 0xff) << 16); |
| 151 | + } |
| 152 | + else |
| 153 | + { |
| 154 | + tint = (tint >> 16) + (tint & 0xff00) + ((tint & 0xff) << 16); |
| 155 | + } |
| 156 | + |
| 157 | + this.pipeline.drawTextureFrame(frame, x, y, tint, this.globalAlpha, this.currentMatrix, null); |
| 158 | + |
| 159 | + // pipeline.drawTextureFrame(frame, x, y, tint, this.globalAlpha, [1,0,0,1,0,0,0,0,1], null); |
94 | 160 | } |
95 | 161 |
|
96 | 162 | }; |
|
0 commit comments