Skip to content

Commit d98d305

Browse files
committed
Frame.setUVs is a new method that allows you to directly set the canvas and UV data for a frame. Use this if you need to override the values set automatically during frame creation.
1 parent a2c9c3c commit d98d305

1 file changed

Lines changed: 46 additions & 8 deletions

File tree

src/textures/Frame.js

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ var Frame = new Class({
340340

341341
/**
342342
* Sets the width, height, x and y of this Frame.
343-
*
343+
*
344344
* This is called automatically by the constructor
345345
* and should rarely be changed on-the-fly.
346346
*
@@ -454,13 +454,13 @@ var Frame = new Class({
454454
/**
455455
* Takes a crop data object and, based on the rectangular region given, calculates the
456456
* required UV coordinates in order to crop this Frame for WebGL and Canvas rendering.
457-
*
457+
*
458458
* This is called directly by the Game Object Texture Components `setCrop` method.
459459
* Please use that method to crop a Game Object.
460460
*
461461
* @method Phaser.Textures.Frame#setCropUVs
462462
* @since 3.11.0
463-
*
463+
*
464464
* @param {object} crop - The crop data object. This is the `GameObject._crop` property.
465465
* @param {number} x - The x coordinate to start the crop from. Cannot be negative or exceed the Frame width.
466466
* @param {number} y - The y coordinate to start the crop from. Cannot be negative or exceed the Frame height.
@@ -504,7 +504,7 @@ var Frame = new Class({
504504

505505
width = Clamp(width, 0, cw - x);
506506
height = Clamp(height, 0, ch - y);
507-
507+
508508
var cropRight = x + width;
509509
var cropBottom = y + height;
510510

@@ -519,7 +519,7 @@ var Frame = new Class({
519519

520520
ow = iw;
521521
oh = ih;
522-
522+
523523
if (flipX)
524524
{
525525
ox = cx + (cw - (ix - ss.x) - iw);
@@ -528,7 +528,7 @@ var Frame = new Class({
528528
{
529529
ox = cx + (ix - ss.x);
530530
}
531-
531+
532532
if (flipY)
533533
{
534534
oy = cy + (ch - (iy - ss.y) - ih);
@@ -558,7 +558,7 @@ var Frame = new Class({
558558
{
559559
ox = cx + (cw - x - width);
560560
}
561-
561+
562562
if (flipY)
563563
{
564564
oy = cy + (ch - y - height);
@@ -598,7 +598,7 @@ var Frame = new Class({
598598
*
599599
* @method Phaser.Textures.Frame#updateCropUVs
600600
* @since 3.11.0
601-
*
601+
*
602602
* @param {object} crop - The crop data object. This is the `GameObject._crop` property.
603603
* @param {boolean} flipX - Does the parent Game Object have flipX set?
604604
* @param {boolean} flipY - Does the parent Game Object have flipY set?
@@ -610,6 +610,44 @@ var Frame = new Class({
610610
return this.setCropUVs(crop, crop.x, crop.y, crop.width, crop.height, flipX, flipY);
611611
},
612612

613+
/**
614+
* Directly sets the canvas and WebGL UV data for this frame.
615+
*
616+
* Use this if you need to override the values that are generated automatically
617+
* when the Frame is created.
618+
*
619+
* @method Phaser.Textures.Frame#setUVs
620+
* @since 3.50.0
621+
*
622+
* @param {number} width - Width of this frame for the Canvas data.
623+
* @param {number} height - Height of this frame for the Canvas data.
624+
* @param {number} u0 - UV u0 value.
625+
* @param {number} v0 - UV v0 value.
626+
* @param {number} u1 - UV u1 value.
627+
* @param {number} v1 - UV v1 value.
628+
*
629+
* @return {Phaser.Textures.Frame} This Frame object.
630+
*/
631+
setUVs: function (width, height, u0, v0, u1, v1)
632+
{
633+
// Canvas data
634+
635+
var cd = this.data.drawImage;
636+
637+
cd.width = width;
638+
cd.height = height;
639+
640+
// WebGL data
641+
642+
this.u0 = u0;
643+
this.v0 = v0;
644+
645+
this.u1 = u1;
646+
this.v1 = v1;
647+
648+
return this;
649+
},
650+
613651
/**
614652
* Updates the internal WebGL UV cache and the drawImage cache.
615653
*

0 commit comments

Comments
 (0)