Skip to content

Commit 870d534

Browse files
committed
Fixed the Loader.preloadSprite crop effect on WebGL.
1 parent a7ff5f8 commit 870d534

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Bug Fixes
6767
* Removed the examples build script from the Gruntfile (fix #592)
6868
* The P2 World wouldn't clear down fully on a State change, now properly clears out contacts, resets the bitmask, etc.
6969
* Button.onInputUpHandler wouldn't set an upFrame for a frame ID of zero, made the check more strict.
70+
* Fixed the Loader.preloadSprite crop effect on WebGL.
7071

7172

7273
Updated:

src/loader/Loader.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,27 +147,27 @@ Phaser.Loader.prototype = {
147147
* This allows you to easily make loading bars for games. Note that Sprite.visible = true will be set when calling this.
148148
*
149149
* @method Phaser.Loader#setPreloadSprite
150-
* @param {Phaser.Sprite|Phaser.Image} sprite - The sprite that will be cropped during the load.
151-
* @param {number} [direction=0] - A value of zero means the sprite width will be cropped, a value of 1 means its height will be cropped.
150+
* @param {Phaser.Sprite|Phaser.Image} sprite - The sprite or image that will be cropped during the load.
151+
* @param {number} [direction=0] - A value of zero means the sprite will be cropped horizontally, a value of 1 means its will be cropped vertically.
152152
*/
153153
setPreloadSprite: function (sprite, direction) {
154154

155155
direction = direction || 0;
156156

157-
this.preloadSprite = { sprite: sprite, direction: direction, width: sprite.width, height: sprite.height, crop: null };
157+
this.preloadSprite = { sprite: sprite, direction: direction, width: sprite.width, height: sprite.height, rect: null };
158158

159159
if (direction === 0)
160160
{
161-
// Horizontal crop
162-
this.preloadSprite.crop = new Phaser.Rectangle(0, 0, 1, sprite.height);
161+
// Horizontal rect
162+
this.preloadSprite.rect = new Phaser.Rectangle(0, 0, 1, sprite.height);
163163
}
164164
else
165165
{
166-
// Vertical crop
167-
this.preloadSprite.crop = new Phaser.Rectangle(0, 0, sprite.width, 1);
166+
// Vertical rect
167+
this.preloadSprite.rect = new Phaser.Rectangle(0, 0, sprite.width, 1);
168168
}
169169

170-
sprite.crop(this.preloadSprite.crop);
170+
sprite.crop(this.preloadSprite.rect);
171171

172172
sprite.visible = true;
173173

@@ -1381,11 +1381,13 @@ Phaser.Loader.prototype = {
13811381
{
13821382
if (this.preloadSprite.direction === 0)
13831383
{
1384-
this.preloadSprite.crop.width = Math.floor((this.preloadSprite.width / 100) * this.progress);
1384+
this.preloadSprite.rect.width = Math.floor((this.preloadSprite.width / 100) * this.progress);
1385+
this.preloadSprite.sprite.crop(this.preloadSprite.rect);
13851386
}
13861387
else
13871388
{
1388-
this.preloadSprite.crop.height = Math.floor((this.preloadSprite.height / 100) * this.progress);
1389+
this.preloadSprite.rect.height = Math.floor((this.preloadSprite.height / 100) * this.progress);
1390+
this.preloadSprite.sprite.crop(this.preloadSprite.rect);
13891391
}
13901392
}
13911393

0 commit comments

Comments
 (0)