From 48f6d850c8926bdf84d06d3d786a7a4085a3b446 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Thu, 8 Aug 2013 06:08:53 +0100 Subject: [PATCH] Fixed bug where a Tween with both yoyo and loop enabled would get out of sync. --- Phaser/Game.ts | 2 -- Phaser/tweens/Tween.ts | 9 ++++++++- README.md | 10 ++++------ Tests/phaser.js | 7 +++++-- Tests/sprites/scale sprite 4.js | 4 ++-- Tests/sprites/scale sprite 4.ts | 2 +- Tests/tweens/tween loop 1.js | 6 +++--- Tests/tweens/tween loop 1.ts | 7 +++---- Tests/tweens/tween loop 2.js | 8 ++++---- Tests/tweens/tween loop 2.ts | 9 ++++----- build/phaser.js | 7 +++++-- 11 files changed, 39 insertions(+), 32 deletions(-) diff --git a/Phaser/Game.ts b/Phaser/Game.ts index b62ff852..c8e6b2f3 100644 --- a/Phaser/Game.ts +++ b/Phaser/Game.ts @@ -685,7 +685,6 @@ module Phaser { { this._paused = true; this.onPause.dispatch(); - // Hook to the above this.sound.pauseAll(); this._raf.callback = this.pausedLoop; } @@ -693,7 +692,6 @@ module Phaser { { this._paused = false; this.onResume.dispatch(); - // Hook to the above this.input.reset(); this.sound.resumeAll(); diff --git a/Phaser/tweens/Tween.ts b/Phaser/tweens/Tween.ts index 51626404..bca3efe2 100644 --- a/Phaser/tweens/Tween.ts +++ b/Phaser/tweens/Tween.ts @@ -406,7 +406,7 @@ module Phaser { // We've yoyo'd once already, quit? if (this._loop == false) { - this.onComplete.dispatch(this._object); + this.onComplete.dispatch(this._object); for (var i = 0; i < this._chainedTweens.length; i++) { @@ -415,6 +415,13 @@ module Phaser { return false; } + else + { + // YoYo and Loop are both on + this._yoyoCount = 0; + this.reverse(); + return true; + } } } diff --git a/README.md b/README.md index c7dd13cd..247acc49 100644 --- a/README.md +++ b/README.md @@ -28,21 +28,19 @@ Future Plans * Ability to layer another DOM object and have it controlled by the game somehow. Can then do stacked canvas effects. * Add ability to create extra
s within the game container, layered above/below the canvas * Basic Window UI component (maybe a propogating Group?) +* Add clip support + shape options to Texture Component. ToDo before release ------------------- -* Hook sound/input to the pause/resume signals -* Fix bug in Tween yoyo + loop combo -* Allow camera to directly render to the stage rather than hidden ctx (maybe does this by default? or have under Mobile Optimisations list) +* Tilemap.render - move layers length to var +* Tilemap.destroy needs doing * Investigate bug re: tilemap collision and animation frames -* Add clip support + shape options to Texture Component. * Need to be able to set the current tilemap layer, then the getTileXY default layer uses that one if no other given +* Allow camera to directly render to the stage rather than hidden ctx (maybe does this by default? or have under Mobile Optimisations list) * Sprite collision events * Check bounds/edge points when sprite is only 1x1 sized :) * QuadTree.physics.checkHullIntersection -* Tilemap.render - move layers length to var -* Tilemap.destroy needs doing * Sprite.transform.bottomRight/Left doesn't seem to take origin into account * Stage lost to mute * Bitmap Font support diff --git a/Tests/phaser.js b/Tests/phaser.js index e0648f29..735ab6f1 100644 --- a/Tests/phaser.js +++ b/Tests/phaser.js @@ -10736,6 +10736,11 @@ var Phaser; this._chainedTweens[i].start(); } return false; + } else { + // YoYo and Loop are both on + this._yoyoCount = 0; + this.reverse(); + return true; } } } @@ -18834,13 +18839,11 @@ var Phaser; if(value == true && this._paused == false) { this._paused = true; this.onPause.dispatch(); - // Hook to the above this.sound.pauseAll(); this._raf.callback = this.pausedLoop; } else if(value == false && this._paused == true) { this._paused = false; this.onResume.dispatch(); - // Hook to the above this.input.reset(); this.sound.resumeAll(); if(this.isRunning == false) { diff --git a/Tests/sprites/scale sprite 4.js b/Tests/sprites/scale sprite 4.js index 7e6d98ac..c1e8490d 100644 --- a/Tests/sprites/scale sprite 4.js +++ b/Tests/sprites/scale sprite 4.js @@ -14,8 +14,8 @@ bunny.transform.scale.setTo(0.5, 0.5); // This time let's scale the sprite by a looped tween game.add.tween(bunny.transform.scale).to({ - x: 2, - y: 2 + x: 1.5, + y: 1.5 }, 2000, Phaser.Easing.Elastic.Out, true, 0, true, true); } })(); diff --git a/Tests/sprites/scale sprite 4.ts b/Tests/sprites/scale sprite 4.ts index bc11458d..1b86f846 100644 --- a/Tests/sprites/scale sprite 4.ts +++ b/Tests/sprites/scale sprite 4.ts @@ -24,7 +24,7 @@ bunny.transform.scale.setTo(0.5, 0.5); // This time let's scale the sprite by a looped tween - game.add.tween(bunny.transform.scale).to({ x: 2, y: 2 }, 2000, Phaser.Easing.Elastic.Out, true, 0, true, true); + game.add.tween(bunny.transform.scale).to({ x: 1.5, y: 1.5 }, 2000, Phaser.Easing.Elastic.Out, true, 0, true, true); } diff --git a/Tests/tweens/tween loop 1.js b/Tests/tweens/tween loop 1.js index 080e994e..9978703a 100644 --- a/Tests/tweens/tween loop 1.js +++ b/Tests/tweens/tween loop 1.js @@ -10,10 +10,10 @@ // Here we'll assign the new sprite to the local swirl variable swirl = game.add.sprite(game.stage.centerX, game.stage.centerY, 'swirl'); // Increase the size of the sprite a little so it covers the edges of the stage - swirl.transform.scale.setTo(1.4, 1.4); + swirl.scale.setTo(1.4, 1.4); // Set the origin to the middle of the Sprite to get the effect we need - swirl.transform.origin.setTo(swirl.worldView.halfWidth, swirl.worldView.halfHeight); - // Create a tween that rotates a full 306 degrees and then repeats (loop set to true) + swirl.origin.setTo(0.5, 0.5); + // Create a tween that rotates a full 360 degrees and then repeats (loop set to true) game.add.tween(swirl).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); diff --git a/Tests/tweens/tween loop 1.ts b/Tests/tweens/tween loop 1.ts index 5330ee14..f4805fd6 100644 --- a/Tests/tweens/tween loop 1.ts +++ b/Tests/tweens/tween loop 1.ts @@ -8,7 +8,6 @@ // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('swirl', 'assets/pics/color_wheel_swirl.png'); - } @@ -20,12 +19,12 @@ swirl = game.add.sprite(game.stage.centerX, game.stage.centerY, 'swirl'); // Increase the size of the sprite a little so it covers the edges of the stage - swirl.transform.scale.setTo(1.4, 1.4); + swirl.scale.setTo(1.4, 1.4); // Set the origin to the middle of the Sprite to get the effect we need - swirl.transform.origin.setTo(swirl.worldView.halfWidth, swirl.worldView.halfHeight); + swirl.origin.setTo(0.5, 0.5); - // Create a tween that rotates a full 306 degrees and then repeats (loop set to true) + // Create a tween that rotates a full 360 degrees and then repeats (loop set to true) game.add.tween(swirl).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); } diff --git a/Tests/tweens/tween loop 2.js b/Tests/tweens/tween loop 2.js index c98d5e24..d005dbc1 100644 --- a/Tests/tweens/tween loop 2.js +++ b/Tests/tweens/tween loop 2.js @@ -10,16 +10,16 @@ // Here we'll assign the new sprite to the local swirl variable swirl = game.add.sprite(game.stage.centerX, game.stage.centerY, 'swirl'); // Increase the size of the sprite a little so it covers the edges of the stage - swirl.transform.scale.setTo(1.4, 1.4); + swirl.scale.setTo(1.4, 1.4); // Set the origin to the middle of the Sprite to get the effect we need - swirl.transform.origin.setTo(swirl.worldView.halfWidth, swirl.worldView.halfHeight); - // Create a tween that rotates a full 306 degrees and then repeats (loop set to true) + swirl.origin.setTo(0.5, 0.5); + // Create a tween that rotates a full 360 degrees and then repeats (loop set to true) game.add.tween(swirl).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); game.add.tween(swirl.transform.scale).to({ x: 4, y: 4 - }, 1000, Phaser.Easing.Linear.None, true, 0, true, true); + }, 4000, Phaser.Easing.Linear.None, true, 0, true, true); } })(); diff --git a/Tests/tweens/tween loop 2.ts b/Tests/tweens/tween loop 2.ts index 0c0ac696..ace17d2d 100644 --- a/Tests/tweens/tween loop 2.ts +++ b/Tests/tweens/tween loop 2.ts @@ -8,7 +8,6 @@ // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('swirl', 'assets/pics/color_wheel_swirl.png'); - } @@ -20,14 +19,14 @@ swirl = game.add.sprite(game.stage.centerX, game.stage.centerY, 'swirl'); // Increase the size of the sprite a little so it covers the edges of the stage - swirl.transform.scale.setTo(1.4, 1.4); + swirl.scale.setTo(1.4, 1.4); // Set the origin to the middle of the Sprite to get the effect we need - swirl.transform.origin.setTo(swirl.worldView.halfWidth, swirl.worldView.halfHeight); + swirl.origin.setTo(0.5, 0.5); - // Create a tween that rotates a full 306 degrees and then repeats (loop set to true) + // Create a tween that rotates a full 360 degrees and then repeats (loop set to true) game.add.tween(swirl).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); - game.add.tween(swirl.transform.scale).to({ x: 4, y: 4 }, 1000, Phaser.Easing.Linear.None, true, 0, true, true); + game.add.tween(swirl.transform.scale).to({ x: 4, y: 4 }, 4000, Phaser.Easing.Linear.None, true, 0, true, true); } diff --git a/build/phaser.js b/build/phaser.js index e0648f29..735ab6f1 100644 --- a/build/phaser.js +++ b/build/phaser.js @@ -10736,6 +10736,11 @@ var Phaser; this._chainedTweens[i].start(); } return false; + } else { + // YoYo and Loop are both on + this._yoyoCount = 0; + this.reverse(); + return true; } } } @@ -18834,13 +18839,11 @@ var Phaser; if(value == true && this._paused == false) { this._paused = true; this.onPause.dispatch(); - // Hook to the above this.sound.pauseAll(); this._raf.callback = this.pausedLoop; } else if(value == false && this._paused == true) { this._paused = false; this.onResume.dispatch(); - // Hook to the above this.input.reset(); this.sound.resumeAll(); if(this.isRunning == false) {