diff --git a/examples/assets/misc/feedback.png b/examples/assets/misc/feedback.png new file mode 100644 index 000000000..92df51b74 Binary files /dev/null and b/examples/assets/misc/feedback.png differ diff --git a/examples/collision/sprite vs group.php b/examples/collision/sprite vs group.php index 7ba31e37a..e061c608f 100644 --- a/examples/collision/sprite vs group.php +++ b/examples/collision/sprite vs group.php @@ -7,7 +7,7 @@ (function () { - var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update }); + var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render }); function preload() { @@ -88,6 +88,13 @@ } + function render () { + + game.debug.renderQuadTree(game.physics.quadTree); + + } + + })(); diff --git a/examples/games/invaders.php b/examples/games/invaders.php index 0499acffe..89c913a39 100644 --- a/examples/games/invaders.php +++ b/examples/games/invaders.php @@ -23,8 +23,6 @@ var bullets; var bulletTime = 0; - var pickle; - function create() { player = game.add.sprite(400, 500, 'ship'); @@ -36,13 +34,12 @@ { for (var x = 0; x < 10; x++) { - aliens.create(170 + x * 48, 100 + y * 50, 'alien'); + aliens.create(x * 48, y * 50, 'alien'); } } - // Shows off a known bug: - // aliens.x = 100; - // aliens.y = 50; + aliens.x = 100; + aliens.y = 50; bullets = game.add.group(null, 'bullets'); @@ -52,18 +49,15 @@ b.name = 'bullet' + i; b.exists = false; b.visible = false; + b.anchor.setTo(0.5, 1); b.events.onOutOfBounds.add(resetBullet, this); } - // Shows off a known bug: - // var tween = game.add.tween(aliens).to({x: 200}, 3000, Phaser.Easing.Linear.None, true, 0, 1000, true); - // tween.onComplete.add(descend, this); + var tween = game.add.tween(aliens).to({x: 200}, 3000, Phaser.Easing.Linear.None, true, 0, 1000, true); + tween.onComplete.add(descend, this); } - function overAlien () { - console.log('over pickle'); - } function descend() { aliens.y += 10; @@ -100,7 +94,7 @@ if (bullet) { - bullet.reset(player.x + 6, player.y - 8); + bullet.reset(player.x, player.y - 8); bullet.velocity.y = -300; bulletTime = game.time.now + 250; } @@ -122,7 +116,7 @@ function render () { - aliens.forEach(renderBounds, this); + // aliens.forEach(renderBounds, this); game.debug.renderQuadTree(game.physics.quadTree); diff --git a/examples/head.php b/examples/head.php index fd873fd77..4121f0e60 100644 --- a/examples/head.php +++ b/examples/head.php @@ -9,9 +9,12 @@ if (isset($mobile)) { - ?> - - '; + } + + if (isset($css)) + { + echo " "; } ?> diff --git a/src/core/Game.js b/src/core/Game.js index 41c63da71..7f14380f9 100644 --- a/src/core/Game.js +++ b/src/core/Game.js @@ -391,6 +391,8 @@ Phaser.Game.prototype = { this.state.update(); this.plugins.update(); + this.world.postUpdate(); + this.renderer.render(this.stage._stage); this.plugins.render(); this.state.render(); diff --git a/src/core/World.js b/src/core/World.js index 4fbbd8c62..5f100a6d6 100644 --- a/src/core/World.js +++ b/src/core/World.js @@ -112,6 +112,30 @@ Phaser.World.prototype = { }, + /** + * This is called automatically every frame, and is where main logic happens. + * @method update + */ + postUpdate: function () { + + if (this.game.stage._stage.first._iNext) + { + var currentNode = this.game.stage._stage.first._iNext; + + do + { + if (currentNode['postUpdate']) + { + currentNode.postUpdate(); + } + + currentNode = currentNode._iNext; + } + while (currentNode != this.game.stage._stage.last._iNext) + } + + }, + /** * Updates the size of this world. * @method setSize diff --git a/src/gameobjects/Sprite.js b/src/gameobjects/Sprite.js index d3fdb6dff..160fc8f16 100644 --- a/src/gameobjects/Sprite.js +++ b/src/gameobjects/Sprite.js @@ -210,17 +210,8 @@ Phaser.Sprite.prototype.preUpdate = function() { this._cache.dirty = true; } - this._cache.x = this.x - (this.game.world.camera.x * this.scrollFactor.x); - this._cache.y = this.y - (this.game.world.camera.y * this.scrollFactor.y); - - // If this sprite or the camera have moved then let's update everything - // Note: The actual position shouldn't be changed if this item is inside a Group? - if (this.position.x != this._cache.x || this.position.y != this._cache.y) - { - this.position.x = this._cache.x; - this.position.y = this._cache.y; - this._cache.dirty = true; - } + // this._cache.x = this.x - (this.game.world.camera.x * this.scrollFactor.x); + // this._cache.y = this.y - (this.game.world.camera.y * this.scrollFactor.y); if (this.visible) { @@ -281,21 +272,6 @@ Phaser.Sprite.prototype.preUpdate = function() { this.updateBounds(); } - // } - // else - // { - // We still need to work out the bounds in case the camera has moved - // but we can't use the local or worldTransform to do it, as Pixi resets that if a Sprite is invisible. - // So we'll compare against the cached state + new position. - // if (this._cache.dirty && this.visible == false) - // { - // this.bounds.x -= this._cache.boundsX - this._cache.x; - // this._cache.boundsX = this._cache.x; - - // this.bounds.y -= this._cache.boundsY - this._cache.y; - // this._cache.boundsY = this._cache.y; - // } - // } // Re-run the camera visibility check if (this._cache.dirty) @@ -312,7 +288,7 @@ Phaser.Sprite.prototype.preUpdate = function() { this.body.updateBounds(this.center.x, this.center.y, this._cache.scaleX, this._cache.scaleY); } - this.body.update(); + this.body.preUpdate(); } @@ -320,7 +296,13 @@ Phaser.Sprite.prototype.postUpdate = function() { if (this.exists) { + // The sprite is positioned in this call, after taking into consideration motion updates and collision this.body.postUpdate(); + + this.position.x -= (this.game.world.camera.x * this.scrollFactor.x); + this.position.y -= (this.game.world.camera.y * this.scrollFactor.y); + this.x -= (this.game.world.camera.x * this.scrollFactor.x); + this.y -= (this.game.world.camera.y * this.scrollFactor.y); } } diff --git a/src/physics/arcade/ArcadePhysics.js b/src/physics/arcade/ArcadePhysics.js index 7db7a380f..6cba4a133 100644 --- a/src/physics/arcade/ArcadePhysics.js +++ b/src/physics/arcade/ArcadePhysics.js @@ -380,11 +380,11 @@ Phaser.Physics.Arcade.prototype = { this._result = (this.separateX(body1, body2) || this.separateY(body1, body2)); - if (this._result) - { - body1.postUpdate(); - body2.postUpdate(); - } + // if (this._result) + // { + // body1.postUpdate(); + // body2.postUpdate(); + // } }, diff --git a/src/physics/arcade/Body.js b/src/physics/arcade/Body.js index d961946e6..d2aac9362 100644 --- a/src/physics/arcade/Body.js +++ b/src/physics/arcade/Body.js @@ -7,6 +7,8 @@ Phaser.Physics.Arcade.Body = function (sprite) { this.x = sprite.x; this.y = sprite.y; + this.preX = sprite.x; + this.preY = sprite.y; this.lastX = sprite.x; this.lastY = sprite.y; @@ -82,7 +84,7 @@ Phaser.Physics.Arcade.Body.prototype = { }, - update: function () { + preUpdate: function () { // Store and reset collision flags this.wasTouching.none = this.touching.none; @@ -97,13 +99,16 @@ Phaser.Physics.Arcade.Body.prototype = { this.touching.left = false; this.touching.right = false; - this.lastX = this.x; - this.lastY = this.y; + this.preX = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x; + this.preY = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y; this.rotation = this.sprite.angle; + this.x = this.preX; + this.y = this.preY; + // There is a bug here in that the worldTransform values are what should be used, otherwise the quadTree gets the wrong rect given to it - this.x = (this.sprite.x - (this.sprite.anchor.x * this.width)) + this.offset.x; - this.y = (this.sprite.y - (this.sprite.anchor.y * this.height)) + this.offset.y; + // this.x = (this.sprite.x - (this.sprite.anchor.x * this.width)) + this.offset.x; + // this.y = (this.sprite.y - (this.sprite.anchor.y * this.height)) + this.offset.y; // this.x = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x; // this.y = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y; @@ -124,20 +129,6 @@ Phaser.Physics.Arcade.Body.prototype = { this.game.physics.quadTree.insert(this); } - if (this.deltaX() != 0) - { - this.sprite.x -= this.deltaX(); - } - - if (this.deltaY() != 0) - { - this.sprite.y -= this.deltaY(); - } - - // Adjust the sprite based on all of the above, so the x/y coords will be correct going into the State update - this.sprite.x = this.x - this.offset.x + (this.sprite.anchor.x * this.width); - this.sprite.y = this.y - this.offset.y + (this.sprite.anchor.y * this.height); - if (this.allowRotation) { this.sprite.angle = this.rotation; @@ -147,14 +138,43 @@ Phaser.Physics.Arcade.Body.prototype = { postUpdate: function () { - this.sprite.x = this.x - this.offset.x + (this.sprite.anchor.x * this.width); - this.sprite.y = this.y - this.offset.y + (this.sprite.anchor.y * this.height); - - if (this.allowRotation) + if (this.deltaX() != 0) { - this.sprite.angle = this.rotation; + this.sprite.position.x += this.deltaX(); + this.sprite.x += this.deltaX(); } + if (this.deltaY() != 0) + { + this.sprite.position.y += this.deltaY(); + this.sprite.y += this.deltaY(); + } + + + // this._cache.x = this.x - (this.game.world.camera.x * this.scrollFactor.x); + // this._cache.y = this.y - (this.game.world.camera.y * this.scrollFactor.y); + + + // if (this.position.x != this._cache.x || this.position.y != this._cache.y) + // { + // this.position.x = this._cache.x; + // this.position.y = this._cache.y; + // this._cache.dirty = true; + // } + + + // Adjust the sprite based on all of the above, so the x/y coords will be correct going into the State update + // this.sprite.x = this.x - this.offset.x + (this.sprite.anchor.x * this.width); + // this.sprite.y = this.y - this.offset.y + (this.sprite.anchor.y * this.height); + + // this.sprite.x = this.x - this.offset.x + (this.sprite.anchor.x * this.width); + // this.sprite.y = this.y - this.offset.y + (this.sprite.anchor.y * this.height); + + // if (this.allowRotation) + // { + // this.sprite.angle = this.rotation; + // } + }, checkWorldBounds: function () { @@ -206,27 +226,31 @@ Phaser.Physics.Arcade.Body.prototype = { this.angularVelocity = 0; this.angularAcceleration = 0; - this.x = (this.sprite.x - (this.sprite.anchor.x * this.width)) + this.offset.x; - this.y = (this.sprite.y - (this.sprite.anchor.y * this.height)) + this.offset.y; - this.lastX = this.x; - this.lastY = this.y; + // this.x = (this.sprite.x - (this.sprite.anchor.x * this.width)) + this.offset.x; + // this.y = (this.sprite.y - (this.sprite.anchor.y * this.height)) + this.offset.y; + // this.lastX = this.x; + // this.lastY = this.y; }, deltaAbsX: function () { + // return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX()); return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX()); }, deltaAbsY: function () { + // return (this.deltaY() > 0 ? this.deltaY() : -this.deltaY()); return (this.deltaY() > 0 ? this.deltaY() : -this.deltaY()); }, deltaX: function () { - return this.x - this.lastX; + // return this.x - this.lastX; + return this.x - this.preX; }, deltaY: function () { - return this.y - this.lastY; + // return this.y - this.lastY; + return this.y - this.preY; } }; diff --git a/src/sound/Sound.js b/src/sound/Sound.js index a7bf61e05..c4cd3bea5 100644 --- a/src/sound/Sound.js +++ b/src/sound/Sound.js @@ -170,6 +170,8 @@ 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;