Skip to content

Commit 8973423

Browse files
committed
Sprite.frame and AnimationManager.frame wouldn't return the correct index if a sprite sheet was being used unless it had first been set via the setter.
1 parent 52ca720 commit 8973423

3 files changed

Lines changed: 48 additions & 10 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ Version 2.3.0 - "Tarabon" - in dev
6464

6565
### Updates
6666

67+
* TypeScript definitions fixes and updates (thanks @clark-stevenson @TimvdEijnden)
68+
6769
### Bug Fixes
6870

6971
* SoundManager.unlock checks for audio `start` support and falls back to `noteOn` if not found.
72+
* Sprite.frame and AnimationManager.frame wouldn't return the correct index if a sprite sheet was being used unless it had first been set via the setter.
7073

7174
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).
7275

src/animation/AnimationManager.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,6 @@ Phaser.AnimationManager.prototype = {
438438
this._anims = {};
439439
this._outputFrames = [];
440440
this._frameData = null;
441-
this._frameIndex = 0;
442441
this.currentAnim = null;
443442
this.currentFrame = null;
444443
this.sprite = null;
@@ -524,7 +523,7 @@ Object.defineProperty(Phaser.AnimationManager.prototype, 'frame', {
524523

525524
if (this.currentFrame)
526525
{
527-
return this._frameIndex;
526+
return this.currentFrame.index;
528527
}
529528

530529
},
@@ -537,8 +536,6 @@ Object.defineProperty(Phaser.AnimationManager.prototype, 'frame', {
537536

538537
if (this.currentFrame)
539538
{
540-
this._frameIndex = value;
541-
542539
this.sprite.setFrame(this.currentFrame);
543540

544541
if (this.sprite.__tilePattern)

src/core/ScaleManager.js

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* If you need to add a border, margin or any other CSS around your game container, then use a parent element and
3131
* apply the CSS to this instead, otherwise you'll be constantly resizing the shape of the game container.
3232
*
33-
* - The Display canvas layout CSS styles (ie. margins, size) should not be altered/specified as
33+
* - The Display canvas layout CSS styles (i.e. margins, size) should not be altered/specified as
3434
* they may be updated by the ScaleManager.
3535
*
3636
* @description
@@ -1161,6 +1161,7 @@ Phaser.ScaleManager.prototype = {
11611161
{
11621162
this.dom.getOffset(this.game.canvas, this.offset);
11631163
}
1164+
11641165
this.bounds.setTo(this.offset.x, this.offset.y, this.width, this.height);
11651166

11661167
// Can be invoked in boot pre-input
@@ -2158,10 +2159,12 @@ Phaser.ScaleManager.prototype.setSize = Phaser.ScaleManager.prototype.reflowCanv
21582159
Phaser.ScaleManager.prototype.checkOrientationState = function () {
21592160

21602161
var changed = this.updateOrientationState();
2162+
21612163
if (changed)
21622164
{
21632165
this.refresh();
21642166
}
2167+
21652168
return changed;
21662169

21672170
};
@@ -2405,7 +2408,7 @@ Object.defineProperty(Phaser.ScaleManager.prototype, "isFullScreen", {
24052408
});
24062409

24072410
/**
2408-
* Returns true if the browser is in portrait mode.
2411+
* Returns true if the screen orientation is in portrait mode.
24092412
*
24102413
* @name Phaser.ScaleManager#isPortrait
24112414
* @property {boolean} isPortrait
@@ -2420,7 +2423,7 @@ Object.defineProperty(Phaser.ScaleManager.prototype, "isPortrait", {
24202423
});
24212424

24222425
/**
2423-
* Returns true if the browser is in landscape mode.
2426+
* Returns true if the screen orientation is in landscape mode.
24242427
*
24252428
* @name Phaser.ScaleManager#isLandscape
24262429
* @property {boolean} isLandscape
@@ -2435,17 +2438,52 @@ Object.defineProperty(Phaser.ScaleManager.prototype, "isLandscape", {
24352438
});
24362439

24372440
/**
2438-
* The _last known_ orientation value of the game. A value of 90 is landscape and 0 is portrait.
2441+
* The _last known_ orientation value of the screen. A value of 90 is landscape and 0 is portrait.
24392442
* @name Phaser.ScaleManager#orientation
24402443
* @property {integer} orientation
24412444
* @readonly
24422445
* @deprecated 2.2.0 - Use {@link #screenOrientation} instead.
24432446
*/
24442447
Object.defineProperty(Phaser.ScaleManager.prototype, "orientation", {
24452448

2446-
get: function ()
2447-
{
2449+
get: function () {
24482450
return (this.classifyOrientation(this.screenOrientation) === 'portrait' ? 0 : 90);
24492451
}
24502452

24512453
});
2454+
2455+
/**
2456+
* Returns true if the game dimensions are portrait (height > width).
2457+
* This is especially useful to check when using the RESIZE scale mode
2458+
* but wanting to maintain game orientation on desktop browsers,
2459+
* where typically the screen orientation will always be landscape regardless of the browser viewport.
2460+
*
2461+
* @name Phaser.ScaleManager#isGamePortrait
2462+
* @property {boolean} isGamePortrait
2463+
* @readonly
2464+
*/
2465+
Object.defineProperty(Phaser.ScaleManager.prototype, "isGamePortrait", {
2466+
2467+
get: function () {
2468+
return (this.height > this.width);
2469+
}
2470+
2471+
});
2472+
2473+
/**
2474+
* Returns true if the game dimensions are landscape (width > height).
2475+
* This is especially useful to check when using the RESIZE scale mode
2476+
* but wanting to maintain game orientation on desktop browsers,
2477+
* where typically the screen orientation will always be landscape regardless of the browser viewport.
2478+
*
2479+
* @name Phaser.ScaleManager#isGameLandscape
2480+
* @property {boolean} isGameLandscape
2481+
* @readonly
2482+
*/
2483+
Object.defineProperty(Phaser.ScaleManager.prototype, "isGameLandscape", {
2484+
2485+
get: function () {
2486+
return (this.width > this.height);
2487+
}
2488+
2489+
});

0 commit comments

Comments
 (0)