Skip to content

Commit 0dfc980

Browse files
committed
Fixed lots of jsdos and moved the frame.cutX/Y addition into each function, allowing the x/y defaults to work again. Fix phaserjs#4528
1 parent 2c8a5d3 commit 0dfc980

1 file changed

Lines changed: 39 additions & 25 deletions

File tree

src/gameobjects/rendertexture/RenderTexture.js

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ var RenderTexture = new Class({
321321
* @since 3.10.0
322322
*
323323
* @param {number} width - The new width of the Render Texture.
324-
* @param {number} [height] - The new height of the Render Texture. If not specified, will be set the same as the `width`.
324+
* @param {number} [height=width] - The new height of the Render Texture. If not specified, will be set the same as the `width`.
325325
*
326326
* @return {this} This Render Texture.
327327
*/
@@ -331,10 +331,9 @@ var RenderTexture = new Class({
331331

332332
if (width !== this.width || height !== this.height)
333333
{
334-
335-
if (this.frame.name === '__BASE') // resize the texture
334+
if (this.frame.name === '__BASE')
336335
{
337-
336+
// Tesize the texture
338337
this.canvas.width = width;
339338
this.canvas.height = height;
340339

@@ -360,14 +359,23 @@ var RenderTexture = new Class({
360359

361360
this.width = width;
362361
this.height = height;
363-
364362
}
365363
}
366-
else // resize the frame
364+
else
367365
{
366+
// Resize the frame
367+
368368
var baseFrame = this.texture.getSourceImage();
369-
if (this.frame.cutX + width > baseFrame.width) { width = baseFrame.width - this.frame.cutX; }
370-
if (this.frame.cutY + height > baseFrame.height) { height = baseFrame.height - this.frame.cutY; }
369+
370+
if (this.frame.cutX + width > baseFrame.width)
371+
{
372+
width = baseFrame.width - this.frame.cutX;
373+
}
374+
375+
if (this.frame.cutY + height > baseFrame.height)
376+
{
377+
height = baseFrame.height - this.frame.cutY;
378+
}
371379

372380
this.frame.setSize(width, height, this.frame.cutX, this.frame.cutY);
373381
}
@@ -713,7 +721,7 @@ var RenderTexture = new Class({
713721

714722
pipeline.projOrtho(0, this.texture.width, 0, this.texture.height, -1000.0, 1000.0);
715723

716-
this.batchList(entries, x + this.frame.cutX, y + this.frame.cutY, alpha, tint);
724+
this.batchList(entries, x, y, alpha, tint);
717725

718726
pipeline.flush();
719727

@@ -727,7 +735,7 @@ var RenderTexture = new Class({
727735
{
728736
this.renderer.setContext(this.context);
729737

730-
this.batchList(entries, x + this.frame.cutX, y + this.frame.cutY, alpha, tint);
738+
this.batchList(entries, x, y, alpha, tint);
731739

732740
this.renderer.setContext();
733741
}
@@ -833,8 +841,8 @@ var RenderTexture = new Class({
833841
* @since 3.12.0
834842
*
835843
* @param {array} children - The array of Game Objects to draw.
836-
* @param {number} x - The x position to offset the Game Object by.
837-
* @param {number} y - The y position to offset the Game Object by.
844+
* @param {number} [x] - The x position to offset the Game Object by.
845+
* @param {number} [y] - The y position to offset the Game Object by.
838846
* @param {number} [alpha] - The alpha to use. If not specified it uses the `globalAlpha` property.
839847
* @param {number} [tint] - The tint color to use. If not specified it uses the `globalTint` property.
840848
*/
@@ -885,14 +893,17 @@ var RenderTexture = new Class({
885893
* @since 3.12.0
886894
*
887895
* @param {array} children - The array of Game Objects to draw.
888-
* @param {number} x - The x position to offset the Game Object by.
889-
* @param {number} y - The y position to offset the Game Object by.
896+
* @param {number} [x=0] - The x position to offset the Game Object by.
897+
* @param {number} [y=0] - The y position to offset the Game Object by.
890898
*/
891899
batchGroup: function (children, x, y)
892900
{
893901
if (x === undefined) { x = 0; }
894902
if (y === undefined) { y = 0; }
895903

904+
x += this.frame.cutX;
905+
y += this.frame.cutY;
906+
896907
for (var i = 0; i < children.length; i++)
897908
{
898909
var entry = children[i];
@@ -915,8 +926,8 @@ var RenderTexture = new Class({
915926
* @since 3.12.0
916927
*
917928
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to draw.
918-
* @param {number} x - The x position to draw the Game Object at.
919-
* @param {number} y - The y position to draw the Game Object at.
929+
* @param {number} [x] - The x position to draw the Game Object at.
930+
* @param {number} [y] - The y position to draw the Game Object at.
920931
*/
921932
batchGameObjectWebGL: function (gameObject, x, y)
922933
{
@@ -931,8 +942,8 @@ var RenderTexture = new Class({
931942
this.renderer.setBlendMode(gameObject.blendMode);
932943
}
933944

934-
gameObject.setPosition(x, y);
935-
945+
gameObject.setPosition(x + this.frame.cutX, y + this.frame.cutY);
946+
936947
gameObject.renderWebGL(this.renderer, gameObject, 0, this.camera, null);
937948

938949
gameObject.setPosition(prevX, prevY);
@@ -946,8 +957,8 @@ var RenderTexture = new Class({
946957
* @since 3.12.0
947958
*
948959
* @param {Phaser.GameObjects.GameObject} gameObject - The Game Object to draw.
949-
* @param {number} x - The x position to draw the Game Object at.
950-
* @param {number} y - The y position to draw the Game Object at.
960+
* @param {number} [x] - The x position to draw the Game Object at.
961+
* @param {number} [y] - The y position to draw the Game Object at.
951962
*/
952963
batchGameObjectCanvas: function (gameObject, x, y)
953964
{
@@ -964,7 +975,7 @@ var RenderTexture = new Class({
964975
gameObject.blendMode = BlendModes.ERASE;
965976
}
966977

967-
gameObject.setPosition(x, y);
978+
gameObject.setPosition(x + this.frame.cutX, y + this.frame.cutY);
968979

969980
gameObject.renderCanvas(this.renderer, gameObject, 0, this.camera, null);
970981

@@ -985,8 +996,8 @@ var RenderTexture = new Class({
985996
*
986997
* @param {string} key - The key of the texture to be used, as stored in the Texture Manager.
987998
* @param {(string|integer)} [frame] - The name or index of the frame within the Texture.
988-
* @param {number} x - The x position to offset the Game Object by.
989-
* @param {number} y - The y position to offset the Game Object by.
999+
* @param {number} [x=0] - The x position to offset the Game Object by.
1000+
* @param {number} [y=0] - The y position to offset the Game Object by.
9901001
* @param {number} [alpha] - The alpha to use. If not specified it uses the `globalAlpha` property.
9911002
* @param {number} [tint] - The tint color to use. If not specified it uses the `globalTint` property.
9921003
*
@@ -1010,15 +1021,18 @@ var RenderTexture = new Class({
10101021
* @since 3.12.0
10111022
*
10121023
* @param {Phaser.Textures.Frame} textureFrame - The Texture Frame to draw.
1013-
* @param {number} x - The x position to draw the Frame at.
1014-
* @param {number} y - The y position to draw the Frame at.
1024+
* @param {number} [x=0] - The x position to draw the Frame at.
1025+
* @param {number} [y=0] - The y position to draw the Frame at.
10151026
* @param {number} [tint] - A tint color to be applied to the frame drawn to the Render Texture.
10161027
*/
10171028
batchTextureFrame: function (textureFrame, x, y, alpha, tint)
10181029
{
10191030
if (x === undefined) { x = 0; }
10201031
if (y === undefined) { y = 0; }
10211032

1033+
x += this.frame.cutX;
1034+
y += this.frame.cutY;
1035+
10221036
if (this.gl)
10231037
{
10241038
this.pipeline.batchTextureFrame(textureFrame, x, y, tint, alpha, this.camera.matrix, null);

0 commit comments

Comments
 (0)