From 4b177e0a9bef1c68397288dd8326ec08bb4c87d2 Mon Sep 17 00:00:00 2001 From: Webeled Date: Mon, 30 Sep 2013 13:26:56 +0100 Subject: [PATCH] Manual update --- src/animation/Animation.js | 4 +-- src/animation/AnimationManager.js | 16 +++++++++++ src/core/StateManager.js | 4 ++- src/gameobjects/Button.js | 1 + src/gameobjects/Sprite.js | 23 ++++++++++++++-- src/particles/arcade/Emitter.js | 2 +- src/physics/arcade/ArcadePhysics.js | 4 +-- src/sound/Sound.js | 41 ++++++++++++++++++++++++----- src/sound/SoundManager.js | 2 -- src/tween/Tween.js | 6 ++++- src/tween/TweenManager.js | 3 ++- 11 files changed, 87 insertions(+), 19 deletions(-) diff --git a/src/animation/Animation.js b/src/animation/Animation.js index 4604a99a..90f456cf 100644 --- a/src/animation/Animation.js +++ b/src/animation/Animation.js @@ -223,7 +223,7 @@ Phaser.Animation.prototype = { { if (this.looped) { - this._frameIndex = this._frameIndex - this._frames.length; + this._frameIndex %= this._frames.length; this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]); if (this.currentFrame) @@ -401,4 +401,4 @@ Phaser.Animation.generateFrameNames = function (prefix, min, max, suffix, zeroPa return output; -} \ No newline at end of file +} diff --git a/src/animation/AnimationManager.js b/src/animation/AnimationManager.js index f6e40ea3..9bee583a 100644 --- a/src/animation/AnimationManager.js +++ b/src/animation/AnimationManager.js @@ -305,6 +305,22 @@ Object.defineProperty(Phaser.AnimationManager.prototype, "frameTotal", { }); +Object.defineProperty(Phaser.AnimationManager.prototype, "paused", { + + get: function () { + + return this.currentAnim.isPaused; + + }, + + set: function (value) { + + this.currentAnim.paused = value; + + } + +}); + Object.defineProperty(Phaser.AnimationManager.prototype, "frame", { /** diff --git a/src/core/StateManager.js b/src/core/StateManager.js index 86a2b8c6..da190432 100644 --- a/src/core/StateManager.js +++ b/src/core/StateManager.js @@ -235,7 +235,9 @@ Phaser.StateManager.prototype = { this.onShutDownCallback.call(this.callbackContext); } - if (clearWorld) { + if (clearWorld) + { + this.game.tweens.removeAll(); this.game.world.destroy(); diff --git a/src/gameobjects/Button.js b/src/gameobjects/Button.js index 171ed086..ddf0871f 100644 --- a/src/gameobjects/Button.js +++ b/src/gameobjects/Button.js @@ -151,6 +151,7 @@ Phaser.Button.prototype.onInputOutHandler = function (pointer) { { this.onInputOut.dispatch(this, pointer); } + }; Phaser.Button.prototype.onInputDownHandler = function (pointer) { diff --git a/src/gameobjects/Sprite.js b/src/gameobjects/Sprite.js index d10f366a..dbb2337a 100644 --- a/src/gameobjects/Sprite.js +++ b/src/gameobjects/Sprite.js @@ -363,8 +363,8 @@ Phaser.Sprite.prototype.reset = function(x, y) { this.x = x; this.y = y; - this.position.x = x; - this.position.y = y; + this.position.x = this.x - (this.game.world.camera.x * this.scrollFactor.x); + this.position.y = this.y - (this.game.world.camera.y * this.scrollFactor.y); this.alive = true; this.exists = true; this.visible = true; @@ -470,6 +470,25 @@ Phaser.Sprite.prototype.getBounds = function(rect) { } +/** +* Play an animation based on the given key. The animation should previously have been added via sprite.animations.add() +* If the requested animation is already playing this request will be ignored. If you need to reset an already running animation do so directly on the Animation object itself. +* +* @method play +* @param {String} name The name of the animation to be played, e.g. "fire", "walk", "jump". +* @param {Number} [frameRate=null] The framerate to play the animation at. The speed is given in frames per second. If not provided the previously set frameRate of the Animation is used. +* @param {Boolean} [loop=null] Should the animation be looped after playback. If not provided the previously set loop value of the Animation is used. +* @return {Phaser.Animation} A reference to playing Animation instance. +*/ +Phaser.Sprite.prototype.play = function (name, frameRate, loop) { + + if (this.animations) + { + this.animations.play(name, frameRate, loop); + } + +} + Object.defineProperty(Phaser.Sprite.prototype, 'angle', { get: function() { diff --git a/src/particles/arcade/Emitter.js b/src/particles/arcade/Emitter.js index d8d886f3..c3fb007c 100644 --- a/src/particles/arcade/Emitter.js +++ b/src/particles/arcade/Emitter.js @@ -358,7 +358,7 @@ Phaser.Particles.Arcade.Emitter.prototype.emitParticle = function () { if (this.width > 1 || this.height > 1) { - particle.reset(this.emiteX - this.game.rnd.integerInRange(this.left, this.right), this.emiteY - this.game.rnd.integerInRange(this.top, this.bottom)); + particle.reset(this.game.rnd.integerInRange(this.left, this.right), this.game.rnd.integerInRange(this.top, this.bottom)); } else { diff --git a/src/physics/arcade/ArcadePhysics.js b/src/physics/arcade/ArcadePhysics.js index 57eb4b63..1402007a 100644 --- a/src/physics/arcade/ArcadePhysics.js +++ b/src/physics/arcade/ArcadePhysics.js @@ -51,13 +51,13 @@ Phaser.Physics.Arcade.prototype = { body.rotation += body.angularVelocity * this.game.time.physicsElapsed; // Horizontal - this._velocityDelta = (this.computeVelocity(1, body, body.velocity.x, body.acceleration.x, body.drag.x) - body.velocity.x) / 2; + this._velocityDelta = (this.computeVelocity(1, body, body.velocity.x, body.acceleration.x, body.drag.x, body.maxVelocity.x) - body.velocity.x) / 2; body.velocity.x += this._velocityDelta; this._delta = body.velocity.x * this.game.time.physicsElapsed; body.x += this._delta; // Vertical - this._velocityDelta = (this.computeVelocity(2, body, body.velocity.y, body.acceleration.y, body.drag.y) - body.velocity.y) / 2; + this._velocityDelta = (this.computeVelocity(2, body, body.velocity.y, body.acceleration.y, body.drag.y, body.maxVelocity.y) - body.velocity.y) / 2; body.velocity.y += this._velocityDelta; this._delta = body.velocity.y * this.game.time.physicsElapsed; body.y += this._delta; diff --git a/src/sound/Sound.js b/src/sound/Sound.js index f466cbfb..6a45bc7b 100644 --- a/src/sound/Sound.js +++ b/src/sound/Sound.js @@ -172,6 +172,7 @@ Phaser.Sound.prototype = { // start and stop are in SECONDS.MS (2.5 = 2500ms, 0.5 = 500ms, etc) // volume is between 0 and 1 + /* addMarker: function (name, start, stop, volume, loop) { volume = volume || 1; @@ -186,6 +187,26 @@ Phaser.Sound.prototype = { loop: loop }; + }, + */ + + // start and stop are in SECONDS.MS (2.5 = 2500ms, 0.5 = 500ms, etc) + // volume is between 0 and 1 + addMarker: function (name, start, duration, volume, loop) { + + volume = volume || 1; + if (typeof loop == 'undefined') { loop = false; } + + this.markers[name] = { + name: name, + start: start, + stop: start + duration, + volume: volume, + duration: duration, + durationMS: duration * 1000, + loop: loop + }; + }, removeMarker: function (name) { @@ -266,19 +287,20 @@ Phaser.Sound.prototype = { position = position || 0; volume = volume || 1; if (typeof loop == 'undefined') { loop = false; } - if (typeof forceRestart == 'undefined') { forceRestart = false; } + if (typeof forceRestart == 'undefined') { forceRestart = true; } - // console.log(this.name + ' play ' + marker + ' position ' + position + ' volume ' + volume + ' loop ' + loop); + console.log(this.name + ' play ' + marker + ' position ' + position + ' volume ' + volume + ' loop ' + loop, 'force', forceRestart); if (this.isPlaying == true && forceRestart == false && this.override == false) { // Use Restart instead + console.log('Use Restart instead'); return; } if (this.isPlaying && this.override) { - // console.log('asked to play ' + marker + ' but already playing ' + this.currentMarker); + console.log('asked to play ' + marker + ' but already playing ' + this.currentMarker); if (this.usingWebAudio) { @@ -305,9 +327,10 @@ Phaser.Sound.prototype = { this.position = this.markers[marker].start; this.volume = this.markers[marker].volume; this.loop = this.markers[marker].loop; - this.duration = this.markers[marker].duration * 1000; + this.duration = this.markers[marker].duration; + + console.log('Marker Loaded: ', marker, 'start:', this.position, 'end: ', this.duration, 'loop', this.loop); - // console.log('marker info loaded', this.loop, this.duration); this._tempMarker = marker; this._tempPosition = this.position; this._tempVolume = this.volume; @@ -315,6 +338,8 @@ Phaser.Sound.prototype = { } else { + console.log('no marker info loaded', marker); + this.position = position; this.volume = volume; this.loop = loop; @@ -355,12 +380,14 @@ Phaser.Sound.prototype = { // Useful to cache this somewhere perhaps? if (typeof this._sound.start === 'undefined') { - this._sound.noteGrainOn(0, this.position, this.duration / 1000); + this._sound.noteGrainOn(0, this.position, this.duration); + // this._sound.noteGrainOn(0, this.position, this.duration / 1000); //this._sound.noteOn(0); // the zero is vitally important, crashes iOS6 without it } else { - this._sound.start(0, this.position, this.duration / 1000); + // this._sound.start(0, this.position, this.duration / 1000); + this._sound.start(0, this.position, this.duration); } this.isPlaying = true; diff --git a/src/sound/SoundManager.js b/src/sound/SoundManager.js index 5464b6f6..252b57d6 100644 --- a/src/sound/SoundManager.js +++ b/src/sound/SoundManager.js @@ -293,8 +293,6 @@ Phaser.SoundManager.prototype = { volume = volume || 1; if (typeof loop == 'undefined') { loop = false; } - - var sound = new Phaser.Sound(this.game, key, volume, loop); this._sounds.push(sound); diff --git a/src/tween/Tween.js b/src/tween/Tween.js index e1161377..07fe841d 100644 --- a/src/tween/Tween.js +++ b/src/tween/Tween.js @@ -246,11 +246,15 @@ Phaser.Tween.prototype = { pause: function () { this._paused = true; + this._pausedTime = this.game.time.now; }, resume: function () { + this._paused = false; - this._startTime += this.game.time.pauseDuration; + + this._startTime += (this.game.time.now - this._pausedTime); + }, update: function ( time ) { diff --git a/src/tween/TweenManager.js b/src/tween/TweenManager.js index c6ab3920..e4c0963f 100644 --- a/src/tween/TweenManager.js +++ b/src/tween/TweenManager.js @@ -39,7 +39,8 @@ Phaser.TweenManager.prototype = { */ removeAll: function () { - this._tweens = []; + this._add.length = 0; + this._tweens.length = 0; },