From 891369b197586ba81e2f3bad22a66dc3446ba01a Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 24 Sep 2013 15:28:29 +0100 Subject: [PATCH] Preparing for 1.0.6 release, but moving physics changes to dev. --- README.md | 24 +- build/phaser.js | 802 ++++++++++++++++++---------- examples/games/starstruck.php | 38 +- src/animation/Animation.js | 48 +- src/physics/arcade/ArcadePhysics.js | 199 ++++++- src/physics/arcade/Body.js | 1 + src/tilemap/Tilemap.js | 4 +- src/tilemap/TilemapLayer.js | 8 + src/tilemap/TilemapRenderer.js | 7 + src/utils/Debug.js | 6 +- 10 files changed, 824 insertions(+), 313 deletions(-) diff --git a/README.md b/README.md index 97b47c66..52a419c9 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Phaser 1.0 Phaser is a fast, free and fun open source game framework for making desktop and mobile browser HTML5 games. It uses [Pixi.js](https://github.com/GoodBoyDigital/pixi.js/) internally for fast 2D Canvas and WebGL rendering. -Version: 1.0.5 - Released: September 20th 2013 +Version: 1.0.6 - Released: September 24th 2013 By Richard Davey, [Photon Storm](http://www.photonstorm.com) @@ -35,7 +35,16 @@ Phaser is everything we ever wanted from an HTML5 game framework. It will power Change Log ---------- -Version 1.0.6 (in progress) +Version 1.0.7 (in progress in the dev branch) + +* Added World.postUpdate - all sprite position changes, as a result of physics, happen here before the render. +* Complete overhaul of Physics.Arcade.Body - now significantly more stable and faster too. +* Updated ArcadePhysics.separateX/Y to use new body system - much better results now. +* QuadTree bug found in 1.0.5 now fixed. The QuadTree is updated properly now using worldTransform values. +* TODO: addMarker hh:mm:ss:ms +* TODO: Direction constants + +Version 1.0.6 (September 24th 2013) * Added check into Pointer.move to always consider a Sprite that has pixelPerfect enabled, regardless of render ID. * BUG: The pixel perfect click check doesn't work if the sprite is part of a texture atlas yet. @@ -46,14 +55,10 @@ Version 1.0.6 (in progress) * New: When loading a Sprite Sheet you can now pass negative values for the frame sizes which specifies the number of rows/columns to load instead (thanks TheJare) * New: BitmapText now supports anchor and has fixed box dimensions (thanks TheJare) * Fixed bug where if a State contains an empty Preloader the Update will not be called (thanks TheJare) -* Added World.postUpdate - all sprite position changes, as a result of physics, happen here before the render. -* Complete overhaul of Physics.Arcade.Body - now significantly more stable and faster too. -* Updated ArcadePhysics.separateX/Y to use new body system - much better results now. -* QuadTree bug found in 1.0.5 now fixed. The QuadTree is updated properly now using worldTransform values. * Several new examples added (cameras, tweens, etc) -* TODO: addMarker hh:mm:ss:ms -* TODO: Direction constants - +* Added in extra checks to halt collision if it involves an empty Group (thanks cang) +* Added time smoothing to Animation update to help frames hopefully not get too out of sync during long animations with high frame rates. +* Added frame skip to Animation.update. If it gets too far behind it will now skip frames to try and catch up. Version 1.0.5 (September 20th 2013) @@ -213,6 +218,7 @@ The following list is not exhaustive and is subject to change: * Joypad support. * Gestures input class. * Flash CC html output support. +* Game parameters read from Google Docs. Right now however our main focus is on documentation and examples, we won't be touching any of the above features until the docs are finished. diff --git a/build/phaser.js b/build/phaser.js index c090eb28..feaf453e 100644 --- a/build/phaser.js +++ b/build/phaser.js @@ -1,7 +1,7 @@ /** * Phaser - http://www.phaser.io * -* v1.0.6 - Built at: Sun, 22 Sep 2013 22:05:45 +0000 +* v1.0.6 - Built at: Tue, 24 Sep 2013 12:29:16 +0000 * * @author Richard Davey http://www.photonstorm.com @photonstorm * @@ -51,7 +51,13 @@ var Phaser = Phaser || { RENDERTEXTURE: 8, TILEMAP: 9, TILEMAPLAYER: 10, - EMITTER: 11 + EMITTER: 11, + + NONE: 0, + LEFT: 1, + RIGHT: 2, + UP: 3, + DOWN: 4 }; @@ -7966,9 +7972,13 @@ Phaser.StateManager.prototype = { if (this._created == false && this.onCreateCallback) { // console.log('Create callback found'); + this._created = true; this.onCreateCallback.call(this.callbackContext); } - this._created = true; + else + { + this._created = true; + } }, @@ -10008,6 +10018,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 @@ -10528,6 +10562,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(); @@ -13958,6 +13994,9 @@ Phaser.Sprite = function (game, x, y, key, frame) { this.x = x; this.y = y; + this.prevX = x; + this.prevY = y; + this.position.x = x; this.position.y = y; @@ -14069,23 +14108,14 @@ 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; - } - if (this.visible) { this.renderOrderID = this.game.world.currentRenderOrderID++; } + this.prevX = this.x; + this.prevY = this.y; + // |a c tx| // |b d ty| // |0 0 1| @@ -14140,21 +14170,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) @@ -14171,7 +14186,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(); } @@ -14179,11 +14194,37 @@ 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._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; + } } } +Phaser.Sprite.prototype.deltaAbsX = function () { + return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX()); +} + +Phaser.Sprite.prototype.deltaAbsY = function () { + return (this.deltaY() > 0 ? this.deltaY() : -this.deltaY()); +} + +Phaser.Sprite.prototype.deltaX = function () { + return this.x - this.prevX; +} + +Phaser.Sprite.prototype.deltaY = function () { + return this.y - this.prevY; +} + /** * Moves the sprite so its center is located on the given x and y coordinates. * Doesn't change the origin of the sprite. @@ -19244,7 +19285,7 @@ Phaser.Rectangle.equals = function (a, b) { */ Phaser.Rectangle.intersection = function (a, b, out) { - out = out || new Phaser.Rectangle; + out = out || new Phaser.Rectangle; if (Phaser.Rectangle.intersects(a, b)) { @@ -20989,6 +21030,9 @@ Phaser.Animation = function (game, parent, name, frameData, frames, delay, loope */ this._frameIndex = 0; + this._frameDiff = 0; + this._frameSkip = 1; + /** * @property {Phaser.Animation.Frame} currentFrame - The currently displayed frame of the Animation. */ @@ -21091,13 +21135,31 @@ Phaser.Animation.prototype = { if (this.isPlaying == true && this.game.time.now >= this._timeNextFrame) { - this._frameIndex++; + this._frameSkip = 1; - if (this._frameIndex == this._frames.length) + // Lagging? + this._frameDiff = this.game.time.now - this._timeNextFrame; + + this._timeLastFrame = this.game.time.now; + + if (this._frameDiff > this.delay) + { + // We need to skip a frame, work out how many + this._frameSkip = Math.floor(this._frameDiff / this.delay); + + this._frameDiff -= (this._frameSkip * this.delay); + } + + // And what's left now? + this._timeNextFrame = this.game.time.now + (this.delay - this._frameDiff); + + this._frameIndex += this._frameSkip; + + if (this._frameIndex >= this._frames.length) { if (this.looped) { - this._frameIndex = 0; + this._frameIndex = this._frameIndex - this._frames.length; this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]); this._parent.setTexture(PIXI.TextureCache[this.currentFrame.uuid]); this._parent.events.onAnimationLoop.dispatch(this._parent, this); @@ -21113,9 +21175,6 @@ Phaser.Animation.prototype = { this._parent.setTexture(PIXI.TextureCache[this.currentFrame.uuid]); } - this._timeLastFrame = this.game.time.now; - this._timeNextFrame = this.game.time.now + this.delay; - return true; } @@ -21170,12 +21229,18 @@ Object.defineProperty(Phaser.Animation.prototype, "frameTotal", { }); +/** + * Sets the current frame to the given frame index and updates the texture cache. + * @param {number} value - The frame to display + * + *//** + * + * Returns the current frame, or if not set the index of the most recent frame. + * @returns {Animation.Frame} + * + */ Object.defineProperty(Phaser.Animation.prototype, "frame", { - /** - * @method frame - * @return {Animation.Frame} Returns the current frame, or if not set the index of the most recent frame. - */ get: function () { if (this.currentFrame !== null) @@ -21189,10 +21254,6 @@ Object.defineProperty(Phaser.Animation.prototype, "frame", { }, - /** - * @method frame - * @return {Number} Sets the current frame to the given frame index and updates the texture cache. - */ set: function (value) { this.currentFrame = this._frameData.getFrame(value); @@ -23768,6 +23829,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; @@ -25060,8 +25123,10 @@ Phaser.Utils.Debug.prototype = { // this.line('ty: ' + sprite.worldTransform[5]); // this.line('skew x: ' + sprite.worldTransform[3]); // this.line('skew y: ' + sprite.worldTransform[1]); - // this.line('dx: ' + sprite.body.deltaX()); - // this.line('dy: ' + sprite.body.deltaY()); + this.line('dx: ' + sprite.body.deltaX()); + this.line('dy: ' + sprite.body.deltaY()); + this.line('sdx: ' + sprite.deltaX()); + this.line('sdy: ' + sprite.deltaY()); // this.line('inCamera: ' + this.game.renderer.spriteRenderer.inCamera(this.game.camera, sprite)); @@ -25827,6 +25892,11 @@ Phaser.Physics.Arcade.prototype = { collideGroupVsTilemap: function (group, tilemap, collideCallback, processCallback, callbackContext) { + if (group.length == 0) + { + return; + } + if (group._container.first._iNext) { var currentNode = group._container.first._iNext; @@ -25881,6 +25951,11 @@ Phaser.Physics.Arcade.prototype = { collideSpriteVsGroup: function (sprite, group, collideCallback, processCallback, callbackContext) { + if (group.length == 0) + { + return; + } + // What is the sprite colliding with in the quadtree? this._potentials = this.quadTree.retrieve(sprite); @@ -25912,6 +25987,11 @@ Phaser.Physics.Arcade.prototype = { collideGroupVsGroup: function (group1, group2, collideCallback, processCallback, callbackContext) { + if (group1.length == 0 || group2.length == 0) + { + return; + } + if (group1._container.first._iNext) { var currentNode = group1._container.first._iNext; @@ -25939,12 +26019,6 @@ Phaser.Physics.Arcade.prototype = { this._result = (this.separateX(body1, body2) || this.separateY(body1, body2)); - if (this._result) - { - body1.postUpdate(); - body2.postUpdate(); - } - }, /** @@ -25955,106 +26029,103 @@ Phaser.Physics.Arcade.prototype = { */ separateX: function (body1, body2) { - // Can't separate two immovable or non-existing bodys + // Can't separate two immovable bodies if (body1.immovable && body2.immovable) { return false; } - // First, get the two body deltas this._overlap = 0; - if (body1.deltaX() != body2.deltaX()) + // Check if the hulls actually overlap + if (Phaser.Rectangle.intersects(body1, body2)) { - // Check if the X hulls actually overlap + this._maxOverlap = body1.deltaAbsX() + body2.deltaAbsX() + this.OVERLAP_BIAS; - this._bounds1.setTo(body1.x - ((body1.deltaX() > 0) ? body1.deltaX() : 0), body1.lastY, body1.width + ((body1.deltaX() > 0) ? body1.deltaX() : -body1.deltaX()), body1.height); - this._bounds2.setTo(body2.x - ((body2.deltaX() > 0) ? body2.deltaX() : 0), body2.lastY, body2.width + ((body2.deltaX() > 0) ? body2.deltaX() : -body2.deltaX()), body2.height); - - if ((this._bounds1.right > this._bounds2.x) && (this._bounds1.x < this._bounds2.right) && (this._bounds1.bottom > this._bounds2.y) && (this._bounds1.y < this._bounds2.bottom)) + if (body1.deltaX() == 0 && body2.deltaX() == 0) { - this._maxOverlap = body1.deltaAbsX() + body2.deltaAbsX() + this.OVERLAP_BIAS; + // They overlap but neither of them are moving + body1.embedded = true; + body2.embedded = true; + } + else if (body1.deltaX() > body2.deltaX()) + { + // Body1 is moving right and/or Body2 is moving left + this._overlap = body1.x + body1.width - body2.x; - // If they did overlap (and can), figure out by how much and flip the corresponding flags - if (body1.deltaX() > body2.deltaX()) + if ((this._overlap > this._maxOverlap) || body1.allowCollision.right == false || body2.allowCollision.left == false) { - this._overlap = body1.x + body1.width - body2.x; - - if ((this._overlap > this._maxOverlap) || body1.allowCollision.right == false || body2.allowCollision.left == false) - { - this._overlap = 0; - } - else - { - body1.touching.right = true; - body2.touching.left = true; - } + this._overlap = 0; } - else if (body1.deltaX() < body2.deltaX()) + else { - this._overlap = body1.x - body2.width - body2.x; - - if ((-this._overlap > this._maxOverlap) || body1.allowCollision.left == false || body2.allowCollision.right == false) - { - this._overlap = 0; - } - else - { - body1.touching.left = true; - body2.touching.right = true; - } + body1.touching.right = true; + body2.touching.left = true; } } - } - - // Then adjust their positions and velocities accordingly (if there was any overlap) - if (this._overlap != 0) - { - body1.overlapX = this._overlap; - body2.overlapX = this._overlap; - - if (body1.customSeparateX || body2.customSeparateX) + else if (body1.deltaX() < body2.deltaX()) { + // Body1 is moving left and/or Body2 is moving right + this._overlap = body1.x - body2.width - body2.x; + + if ((-this._overlap > this._maxOverlap) || body1.allowCollision.left == false || body2.allowCollision.right == false) + { + this._overlap = 0; + } + else + { + body1.touching.left = true; + body2.touching.right = true; + } + } + + // Then adjust their positions and velocities accordingly (if there was any overlap) + if (this._overlap != 0) + { + body1.overlapX = this._overlap; + body2.overlapX = this._overlap; + + if (body1.customSeparateX || body2.customSeparateX) + { + return true; + } + + this._velocity1 = body1.velocity.x; + this._velocity2 = body2.velocity.x; + + if (!body1.immovable && !body2.immovable) + { + this._overlap *= 0.5; + + body1.x = body1.x - this._overlap; + body2.x += this._overlap; + + this._newVelocity1 = Math.sqrt((this._velocity2 * this._velocity2 * body2.mass) / body1.mass) * ((this._velocity2 > 0) ? 1 : -1); + this._newVelocity2 = Math.sqrt((this._velocity1 * this._velocity1 * body1.mass) / body2.mass) * ((this._velocity1 > 0) ? 1 : -1); + this._average = (this._newVelocity1 + this._newVelocity2) * 0.5; + this._newVelocity1 -= this._average; + this._newVelocity2 -= this._average; + + body1.velocity.x = this._average + this._newVelocity1 * body1.bounce.x; + body2.velocity.x = this._average + this._newVelocity2 * body2.bounce.x; + } + else if (!body1.immovable) + { + body1.x = body1.x - this._overlap; + body1.velocity.x = this._velocity2 - this._velocity1 * body1.bounce.x; + } + else if (!body2.immovable) + { + body2.x += this._overlap; + body2.velocity.x = this._velocity1 - this._velocity2 * body2.bounce.x; + } + return true; } - - this._velocity1 = body1.velocity.x; - this._velocity2 = body2.velocity.x; - - if (!body1.immovable && !body2.immovable) - { - this._overlap *= 0.5; - - body1.x = body1.x - this._overlap; - body2.x += this._overlap; - - this._newVelocity1 = Math.sqrt((this._velocity2 * this._velocity2 * body2.mass) / body1.mass) * ((this._velocity2 > 0) ? 1 : -1); - this._newVelocity2 = Math.sqrt((this._velocity1 * this._velocity1 * body1.mass) / body2.mass) * ((this._velocity1 > 0) ? 1 : -1); - this._average = (this._newVelocity1 + this._newVelocity2) * 0.5; - this._newVelocity1 -= this._average; - this._newVelocity2 -= this._average; - - body1.velocity.x = this._average + this._newVelocity1 * body1.bounce.x; - body2.velocity.x = this._average + this._newVelocity2 * body2.bounce.x; - } - else if (!body1.immovable) - { - body1.x = body1.x - this._overlap; - body1.velocity.x = this._velocity2 - this._velocity1 * body1.bounce.x; - } - else if (!body2.immovable) - { - body2.x += this._overlap; - body2.velocity.x = this._velocity1 - this._velocity2 * body2.bounce.x; - } - - return true; - } - else - { - return false; } + return false; + }, /** @@ -26071,110 +26142,110 @@ Phaser.Physics.Arcade.prototype = { return false; } - // First, get the two body deltas this._overlap = 0; - if (body1.deltaY() != body2.deltaY()) + // Check if the hulls actually overlap + if (Phaser.Rectangle.intersects(body1, body2)) { - // Check if the Y hulls actually overlap - this._bounds1.setTo(body1.x, body1.y - ((body1.deltaY() > 0) ? body1.deltaY() : 0), body1.width, body1.height + body1.deltaAbsY()); - this._bounds2.setTo(body2.x, body2.y - ((body2.deltaY() > 0) ? body2.deltaY() : 0), body2.width, body2.height + body2.deltaAbsY()); + this._maxOverlap = body1.deltaAbsY() + body2.deltaAbsY() + this.OVERLAP_BIAS; - if ((this._bounds1.right > this._bounds2.x) && (this._bounds1.x < this._bounds2.right) && (this._bounds1.bottom > this._bounds2.y) && (this._bounds1.y < this._bounds2.bottom)) + if (body1.deltaY() == 0 && body2.deltaY() == 0) { - this._maxOverlap = body1.deltaAbsY() + body2.deltaAbsY() + this.OVERLAP_BIAS; + // They overlap but neither of them are moving + body1.embedded = true; + body2.embedded = true; + } + else if (body1.deltaY() > body2.deltaY()) + { + // Body1 is moving down and/or Body2 is moving up + this._overlap = body1.y + body1.height - body2.y; - // If they did overlap (and can), figure out by how much and flip the corresponding flags - if (body1.deltaY() > body2.deltaY()) + if ((this._overlap > this._maxOverlap) || body1.allowCollision.down == false || body2.allowCollision.up == false) { - this._overlap = body1.y + body1.height - body2.y; - - if ((this._overlap > this._maxOverlap) || body1.allowCollision.down == false || body2.allowCollision.up == false) - { - this._overlap = 0; - } - else - { - body1.touching.down = true; - body2.touching.up = true; - } + this._overlap = 0; } - else if (body1.deltaY() < body2.deltaY()) + else { - this._overlap = body1.y - body2.height - body2.y; - - if ((-this._overlap > this._maxOverlap) || body1.allowCollision.up == false || body2.allowCollision.down == false) - { - this._overlap = 0; - } - else - { - body1.touching.up = true; - body2.touching.down = true; - } + body1.touching.down = true; + body2.touching.up = true; } } - } - - // Then adjust their positions and velocities accordingly (if there was any overlap) - if (this._overlap != 0) - { - body1.overlapY = this._overlap; - body2.overlapY = this._overlap; - - if (body1.customSeparateY || body2.customSeparateY) + else if (body1.deltaY() < body2.deltaY()) { + // Body1 is moving up and/or Body2 is moving down + this._overlap = body1.y - body2.height - body2.y; + + if ((-this._overlap > this._maxOverlap) || body1.allowCollision.up == false || body2.allowCollision.down == false) + { + this._overlap = 0; + } + else + { + body1.touching.up = true; + body2.touching.down = true; + } + } + + // Then adjust their positions and velocities accordingly (if there was any overlap) + if (this._overlap != 0) + { + body1.overlapY = this._overlap; + body2.overlapY = this._overlap; + + if (body1.customSeparateY || body2.customSeparateY) + { + return true; + } + + this._velocity1 = body1.velocity.y; + this._velocity2 = body2.velocity.y; + + if (!body1.immovable && !body2.immovable) + { + this._overlap *= 0.5; + + body1.y = body1.y - this._overlap; + body2.y += this._overlap; + + this._newVelocity1 = Math.sqrt((this._velocity2 * this._velocity2 * body2.mass) / body1.mass) * ((this._velocity2 > 0) ? 1 : -1); + this._newVelocity2 = Math.sqrt((this._velocity1 * this._velocity1 * body1.mass) / body2.mass) * ((this._velocity1 > 0) ? 1 : -1); + this._average = (this._newVelocity1 + this._newVelocity2) * 0.5; + this._newVelocity1 -= this._average; + this._newVelocity2 -= this._average; + + body1.velocity.y = this._average + this._newVelocity1 * body1.bounce.y; + body2.velocity.y = this._average + this._newVelocity2 * body2.bounce.y; + } + else if (!body1.immovable) + { + body1.y = body1.y - this._overlap; + body1.velocity.y = this._velocity2 - this._velocity1 * body1.bounce.y; + + // This is special case code that handles things like horizontal moving platforms you can ride + if (body2.active && body2.moves && (body1.deltaY() > body2.deltaY())) + { + body1.x += body2.x - body2.lastX; + } + } + else if (!body2.immovable) + { + body2.y += this._overlap; + body2.velocity.y = this._velocity1 - this._velocity2 * body2.bounce.y; + + // This is special case code that handles things like horizontal moving platforms you can ride + if (body1.sprite.active && body1.moves && (body1.deltaY() < body2.deltaY())) + { + body2.x += body1.x - body1.lastX; + } + } + return true; } - this._velocity1 = body1.velocity.y; - this._velocity2 = body2.velocity.y; - - if (!body1.immovable && !body2.immovable) - { - this._overlap *= 0.5; - - body1.y = body1.y - this._overlap; - body2.y += this._overlap; - - this._newVelocity1 = Math.sqrt((this._velocity2 * this._velocity2 * body2.mass) / body1.mass) * ((this._velocity2 > 0) ? 1 : -1); - this._newVelocity2 = Math.sqrt((this._velocity1 * this._velocity1 * body1.mass) / body2.mass) * ((this._velocity1 > 0) ? 1 : -1); - this._average = (this._newVelocity1 + this._newVelocity2) * 0.5; - this._newVelocity1 -= this._average; - this._newVelocity2 -= this._average; - - body1.velocity.y = this._average + this._newVelocity1 * body1.bounce.y; - body2.velocity.y = this._average + this._newVelocity2 * body2.bounce.y; - } - else if (!body1.immovable) - { - body1.y = body1.y - this._overlap; - body1.velocity.y = this._velocity2 - this._velocity1 * body1.bounce.y; - - // This is special case code that handles things like horizontal moving platforms you can ride - if (body2.active && body2.moves && (body1.deltaY() > body2.deltaY())) - { - body1.x += body2.x - body2.lastX; - } - } - else if (!body2.immovable) - { - body2.y += this._overlap; - body2.velocity.y = this._velocity1 - this._velocity2 * body2.bounce.y; - - // This is special case code that handles things like horizontal moving platforms you can ride - if (body1.sprite.active && body1.moves && (body1.deltaY() < body2.deltaY())) - { - body2.x += body1.x - body1.lastX; - } - } - - return true; - } - else - { - return false; } + + return false; + }, /** @@ -26190,7 +26261,6 @@ Phaser.Physics.Arcade.prototype = { if (separatedX || separatedY) { - object.body.postUpdate(); return true; } @@ -26371,6 +26441,160 @@ Phaser.Physics.Arcade.prototype = { return false; } + }, + + /** + * Separates the two objects on their x axis + * @param object The GameObject to separate + * @param tile The Tile to separate + * @returns {boolean} Whether the objects in fact touched and were separated along the X axis. + */ + NEWseparateTileX: function (object, x, y, width, height, mass, collideLeft, collideRight, separate) { + + // Can't separate two immovable objects (tiles are always immovable) + if (object.immovable) + { + return false; + } + + this._overlap = 0; + + if (Phaser.Rectangle.intersectsRaw(object, x, x + width, y, y + height)) + { + this._maxOverlap = object.deltaAbsX() + this.OVERLAP_BIAS; + + if (object.deltaX() == 0) + { + // Object is stuck inside a tile and not moving + } + else if (object.deltaX() > 0) + { + // Going right ... + this._overlap = object.x + object.width - x; + + if ((this._overlap > this._maxOverlap) || !object.allowCollision.right || !collideLeft) + { + this._overlap = 0; + } + else + { + object.touching.right = true; + } + } + else if (object.deltaX() < 0) + { + // Going left ... + this._overlap = object.x - width - x; + + if ((-this._overlap > this._maxOverlap) || !object.allowCollision.left || !collideRight) + { + this._overlap = 0; + } + else + { + object.touching.left = true; + } + } + + if (this._overlap != 0) + { + if (separate) + { + object.x = object.x - this._overlap; + + if (object.bounce.x == 0) + { + object.velocity.x = 0; + } + else + { + object.velocity.x = -object.velocity.x * object.bounce.x; + } + } + return true; + } + + } + + return false; + + }, + + /** + * Separates the two objects on their x axis + * @param object The GameObject to separate + * @param tile The Tile to separate + * @returns {boolean} Whether the objects in fact touched and were separated along the X axis. + */ + NEWseparateTileY: function (object, x, y, width, height, mass, collideUp, collideDown, separate) { + + // Can't separate two immovable objects (tiles are always immovable) + if (object.immovable) + { + return false; + } + + this._overlap = 0; + + if (Phaser.Rectangle.intersectsRaw(object, x, x + width, y, y + height)) + { + this._maxOverlap = object.deltaAbsY() + this.OVERLAP_BIAS; + + if (object.deltaY() == 0) + { + // Object is stuck inside a tile and not moving + } + else if (object.deltaY() > 0) + { + // Going down ... + this._overlap = object.bottom - y; + + // if (object.allowCollision.down && collideDown && this._overlap < this._maxOverlap) + if ((this._overlap > this._maxOverlap) || !object.allowCollision.down || !collideDown) + { + this._overlap = 0; + } + else + { + object.touching.down = true; + } + } + else if (object.deltaY() < 0) + { + // Going up ... + this._overlap = object.y - height - y; + + if ((-this._overlap > this._maxOverlap) || !object.allowCollision.up || !collideUp) + { + this._overlap = 0; + } + else + { + object.touching.up = true; + } + } + + if (this._overlap != 0) + { + if (separate) + { + object.y = object.y - this._overlap; + + if (object.bounce.y == 0) + { + object.velocity.y = 0; + } + else + { + object.velocity.y = -object.velocity.y * object.bounce.y; + } + } + return true; + } + } + + return false; + }, /** @@ -26747,8 +26971,8 @@ Phaser.Physics.Arcade.Body = function (sprite) { this.x = sprite.x; this.y = sprite.y; - this.lastX = sprite.x; - this.lastY = sprite.y; + this.preX = sprite.x; + this.preY = sprite.y; // un-scaled original size this.sourceWidth = sprite.currentFrame.sourceSizeW; @@ -26784,6 +27008,7 @@ Phaser.Physics.Arcade.Body = function (sprite) { this.allowCollision = { none: false, any: true, up: true, down: true, left: true, right: true }; this.touching = { none: true, up: false, down: false, left: false, right: false }; this.wasTouching = { none: true, up: false, down: false, left: false, right: false }; + this.facing = Phaser.NONE; this.immovable = false; this.moves = true; @@ -26802,6 +27027,9 @@ Phaser.Physics.Arcade.Body = function (sprite) { this.overlapX = 0; this.overlapY = 0; + // If a body is overlapping with another body, but neither of them are moving (maybe they spawned on-top of each other?) this is set to true + this.embedded = false; + this.collideWorldBounds = false; }; @@ -26822,7 +27050,7 @@ Phaser.Physics.Arcade.Body.prototype = { }, - update: function () { + preUpdate: function () { // Store and reset collision flags this.wasTouching.none = this.touching.none; @@ -26837,15 +27065,14 @@ Phaser.Physics.Arcade.Body.prototype = { this.touching.left = false; this.touching.right = false; - this.lastX = this.x; - this.lastY = this.y; + this.embedded = false; + + 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; - // 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.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; + this.x = this.preX; + this.y = this.preY; if (this.moves) { @@ -26864,31 +27091,47 @@ 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; - } - }, 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); + // Calculate forward-facing edge + if (this.deltaX() == 0 && this.deltaY() == 0) + { + // Can't work it out from the Body, how about from x position? + if (this.sprite.deltaX() == 0 && this.sprite.deltaY() == 0) + { + // still as a statue + } + } + + if (this.deltaX() < 0) + { + this.facing = Phaser.LEFT; + } + else if (this.deltaX() > 0) + { + this.facing = Phaser.RIGHT; + } + + if (this.deltaY() < 0) + { + this.facing = Phaser.UP; + } + else if (this.deltaY() > 0) + { + this.facing = Phaser.DOWN; + } + + if (this.deltaX() != 0) + { + this.sprite.x += this.deltaX(); + } + + if (this.deltaY() != 0) + { + this.sprite.y += this.deltaY(); + } if (this.allowRotation) { @@ -26946,10 +27189,9 @@ 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.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; + this.rotation = this.sprite.angle; }, @@ -26962,11 +27204,11 @@ Phaser.Physics.Arcade.Body.prototype = { }, deltaX: function () { - return this.x - this.lastX; + return this.x - this.preX; }, deltaY: function () { - return this.y - this.lastY; + return this.y - this.preY; } }; @@ -27837,6 +28079,8 @@ Phaser.Tilemap.prototype.parseTiledJSON = function (json, key) { */ Phaser.Tilemap.prototype.generateTiles = function (qty) { + console.log('generating', qty, 'tiles'); + for (var i = 0; i < qty; i++) { this.tiles.push(new Phaser.Tile(this.game, this, i, this.currentLayer.tileWidth, this.currentLayer.tileHeight)); @@ -28744,21 +28988,37 @@ Phaser.Tile.prototype = { this.collideUp = false; this.collideDown = false; - }, - - /** - * Returns a string representation of this object. - * @method toString - * @return {string} a string representation of the object. - **/ - toString: function () { - - // return "[{Tile (index=" + this.index + " collisions=" + this.allowCollisions + " width=" + this.width + " height=" + this.height + ")}]"; - return ''; - } }; + +Object.defineProperty(Phaser.Tile.prototype, "bottom", { + + /** + * The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property. + * @method bottom + * @return {Number} + **/ + get: function () { + return this.y + this.height; + } + +}); + +Object.defineProperty(Phaser.Tile.prototype, "right", { + + /** + * The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties. + * However it does affect the width property. + * @method right + * @return {Number} + **/ + get: function () { + return this.x + this.width; + } + +}); + Phaser.TilemapRenderer = function (game) { this.game = game; diff --git a/examples/games/starstruck.php b/examples/games/starstruck.php index 42bfb566..dc824516 100644 --- a/examples/games/starstruck.php +++ b/examples/games/starstruck.php @@ -38,10 +38,11 @@ map.setCollisionRange(18, 47, true, true, true, true); map.setCollisionRange(53, 69, true, true, true, true); - player = game.add.sprite(32, 32, 'dude'); + // player = game.add.sprite(32, 32, 'dude'); + player = game.add.sprite(250, 220, 'dude'); player.body.bounce.y = 0.2; player.body.collideWorldBounds = true; - player.body.gravity.y = 10; + // player.body.gravity.y = 10; player.animations.add('left', [0, 1, 2, 3], 10, true); player.animations.add('turn', [4], 20, true); @@ -56,6 +57,7 @@ game.physics.collide(player, map); player.body.velocity.x = 0; + player.body.velocity.y = 0; // player.body.acceleration.y = 500; if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) @@ -96,25 +98,33 @@ facing = 'idle'; } } - - if (game.input.keyboard.isDown(Phaser.Keyboard.UP) || game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)) + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { - if (player.body.touching.down && game.time.now > jumpTimer) - { - player.body.velocity.y = -200; - jumpTimer = game.time.now + 500; - } + player.body.velocity.y = -150; } + else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) + { + player.body.velocity.y = 150; + } + + + // if (game.input.keyboard.isDown(Phaser.Keyboard.UP) || game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)) + // { + // if (player.body.touching.down && game.time.now > jumpTimer) + // { + // player.body.velocity.y = -200; + // jumpTimer = game.time.now + 500; + // } + // } } function render() { - // game.debug.renderSpriteCorners(p); - // game.debug.renderSpriteCollision(p, 32, 320); - // game.debug.renderText(player.body.velocity.y, 32, 32, 'rgb(255,255,255)'); - // game.debug.renderText('left: ' + player.body.touching.left, 32, 32, 'rgb(255,255,255)'); - // game.debug.renderText('right: ' + player.body.touching.right, 32, 64, 'rgb(255,255,255)'); + game.debug.renderSpriteInfo(player, 32, 32); + game.debug.renderSpriteCorners(player, false, true); + game.debug.renderSpriteCollision(player, 32, 320); } diff --git a/src/animation/Animation.js b/src/animation/Animation.js index 64c72b9b..a5e8d271 100644 --- a/src/animation/Animation.js +++ b/src/animation/Animation.js @@ -79,6 +79,9 @@ Phaser.Animation = function (game, parent, name, frameData, frames, delay, loope */ this._frameIndex = 0; + this._frameDiff = 0; + this._frameSkip = 1; + /** * @property {Phaser.Animation.Frame} currentFrame - The currently displayed frame of the Animation. */ @@ -181,13 +184,31 @@ Phaser.Animation.prototype = { if (this.isPlaying == true && this.game.time.now >= this._timeNextFrame) { - this._frameIndex++; + this._frameSkip = 1; - if (this._frameIndex == this._frames.length) + // Lagging? + this._frameDiff = this.game.time.now - this._timeNextFrame; + + this._timeLastFrame = this.game.time.now; + + if (this._frameDiff > this.delay) + { + // We need to skip a frame, work out how many + this._frameSkip = Math.floor(this._frameDiff / this.delay); + + this._frameDiff -= (this._frameSkip * this.delay); + } + + // And what's left now? + this._timeNextFrame = this.game.time.now + (this.delay - this._frameDiff); + + this._frameIndex += this._frameSkip; + + if (this._frameIndex >= this._frames.length) { if (this.looped) { - this._frameIndex = 0; + this._frameIndex = this._frameIndex - this._frames.length; this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]); this._parent.setTexture(PIXI.TextureCache[this.currentFrame.uuid]); this._parent.events.onAnimationLoop.dispatch(this._parent, this); @@ -203,9 +224,6 @@ Phaser.Animation.prototype = { this._parent.setTexture(PIXI.TextureCache[this.currentFrame.uuid]); } - this._timeLastFrame = this.game.time.now; - this._timeNextFrame = this.game.time.now + this.delay; - return true; } @@ -260,12 +278,18 @@ Object.defineProperty(Phaser.Animation.prototype, "frameTotal", { }); +/** + * Sets the current frame to the given frame index and updates the texture cache. + * @param {number} value - The frame to display + * + *//** + * + * Returns the current frame, or if not set the index of the most recent frame. + * @returns {Animation.Frame} + * + */ Object.defineProperty(Phaser.Animation.prototype, "frame", { - /** - * @method frame - * @return {Animation.Frame} Returns the current frame, or if not set the index of the most recent frame. - */ get: function () { if (this.currentFrame !== null) @@ -279,10 +303,6 @@ Object.defineProperty(Phaser.Animation.prototype, "frame", { }, - /** - * @method frame - * @return {Number} Sets the current frame to the given frame index and updates the texture cache. - */ set: function (value) { this.currentFrame = this._frameData.getFrame(value); diff --git a/src/physics/arcade/ArcadePhysics.js b/src/physics/arcade/ArcadePhysics.js index 094b6a15..57eb4b63 100644 --- a/src/physics/arcade/ArcadePhysics.js +++ b/src/physics/arcade/ArcadePhysics.js @@ -268,6 +268,11 @@ Phaser.Physics.Arcade.prototype = { collideGroupVsTilemap: function (group, tilemap, collideCallback, processCallback, callbackContext) { + if (group.length == 0) + { + return; + } + if (group._container.first._iNext) { var currentNode = group._container.first._iNext; @@ -322,6 +327,11 @@ Phaser.Physics.Arcade.prototype = { collideSpriteVsGroup: function (sprite, group, collideCallback, processCallback, callbackContext) { + if (group.length == 0) + { + return; + } + // What is the sprite colliding with in the quadtree? this._potentials = this.quadTree.retrieve(sprite); @@ -353,6 +363,11 @@ Phaser.Physics.Arcade.prototype = { collideGroupVsGroup: function (group1, group2, collideCallback, processCallback, callbackContext) { + if (group1.length == 0 || group2.length == 0) + { + return; + } + if (group1._container.first._iNext) { var currentNode = group1._container.first._iNext; @@ -629,6 +644,181 @@ Phaser.Physics.Arcade.prototype = { }, + /** + * Separates the two objects on their x axis + * @param object The GameObject to separate + * @param tile The Tile to separate + * @returns {boolean} Whether the objects in fact touched and were separated along the X axis. + */ + OLDseparateTileX: function (object, x, y, width, height, mass, collideLeft, collideRight, separate) { + + // Can't separate two immovable objects (tiles are always immovable) + if (object.immovable) + { + return false; + } + + // First, get the object delta + this._overlap = 0; + + // console.log('separatedX', x, y, object.deltaX()); + + if (object.deltaX() != 0) + { + this._bounds1.setTo(object.x, object.y, object.width, object.height); + + if ((this._bounds1.right > x) && (this._bounds1.x < x + width) && (this._bounds1.bottom > y) && (this._bounds1.y < y + height)) + { + // The hulls overlap, let's process it + this._maxOverlap = object.deltaAbsX() + this.OVERLAP_BIAS; + + // TODO - We need to check if we're already inside of the tile, i.e. jumping through an n-way tile + // in which case we didn't ought to separate because it'll look like tunneling + + if (object.deltaX() > 0) + { + // Going right ... + this._overlap = object.x + object.width - x; + + if ((this._overlap > this._maxOverlap) || !object.allowCollision.right || !collideLeft) + { + this._overlap = 0; + } + else + { + object.touching.right = true; + } + } + else if (object.deltaX() < 0) + { + // Going left ... + this._overlap = object.x - width - x; + + if ((-this._overlap > this._maxOverlap) || !object.allowCollision.left || !collideRight) + { + this._overlap = 0; + } + else + { + object.touching.left = true; + } + } + } + } + + // Then adjust their positions and velocities accordingly (if there was any overlap) + if (this._overlap != 0) + { + if (separate) + { + object.x = object.x - this._overlap; + + if (object.bounce.x == 0) + { + object.velocity.x = 0; + } + else + { + object.velocity.x = -object.velocity.x * object.bounce.x; + } + } + return true; + } + else + { + return false; + } + + }, + + /** + * Separates the two objects on their x axis + * @param object The GameObject to separate + * @param tile The Tile to separate + * @returns {boolean} Whether the objects in fact touched and were separated along the X axis. + */ + OLDseparateTileY: function (object, x, y, width, height, mass, collideUp, collideDown, separate) { + + // Can't separate two immovable objects (tiles are always immovable) + if (object.immovable) + { + return false; + } + + // First, get the object delta + this._overlap = 0; + + if (object.deltaY() != 0) + { + this._bounds1.setTo(object.x, object.y, object.width, object.height); + + if ((this._bounds1.right > x) && (this._bounds1.x < x + width) && (this._bounds1.bottom > y) && (this._bounds1.y < y + height)) + { + // The hulls overlap, let's process it + + // Not currently used, may need it so keep for now + this._maxOverlap = object.deltaAbsY() + this.OVERLAP_BIAS; + + // TODO - We need to check if we're already inside of the tile, i.e. jumping through an n-way tile + // in which case we didn't ought to separate because it'll look like tunneling + + if (object.deltaY() > 0) + { + // Going down ... + this._overlap = object.bottom - y; + + // if (object.allowCollision.down && collideDown && this._overlap < this._maxOverlap) + if ((this._overlap > this._maxOverlap) || !object.allowCollision.down || !collideDown) + { + this._overlap = 0; + } + else + { + object.touching.down = true; + } + } + else + { + // Going up ... + this._overlap = object.y - height - y; + + if ((-this._overlap > this._maxOverlap) || !object.allowCollision.up || !collideUp) + { + this._overlap = 0; + } + else + { + object.touching.up = true; + } + } + } + } + + // Then adjust their positions and velocities accordingly (if there was any overlap) + if (this._overlap != 0) + { + if (separate) + { + object.y = object.y - this._overlap; + + if (object.bounce.y == 0) + { + object.velocity.y = 0; + } + else + { + object.velocity.y = -object.velocity.y * object.bounce.y; + } + } + return true; + } + else + { + return false; + } + + }, + /** * Separates the two objects on their x axis * @param object The GameObject to separate @@ -645,17 +835,21 @@ Phaser.Physics.Arcade.prototype = { this._overlap = 0; + // Do we have any overlap at all? if (Phaser.Rectangle.intersectsRaw(object, x, x + width, y, y + height)) { this._maxOverlap = object.deltaAbsX() + this.OVERLAP_BIAS; if (object.deltaX() == 0) { - // Object is stuck inside a tile and not moving + // Object is either stuck inside the tile or only overlapping on the Y axis } else if (object.deltaX() > 0) { // Going right ... + + + this._overlap = object.x + object.width - x; if ((this._overlap > this._maxOverlap) || !object.allowCollision.right || !collideLeft) @@ -686,6 +880,7 @@ Phaser.Physics.Arcade.prototype = { { if (separate) { + console.log('x over', this._overlap); object.x = object.x - this._overlap; if (object.bounce.x == 0) @@ -762,6 +957,8 @@ Phaser.Physics.Arcade.prototype = { if (this._overlap != 0) { + console.log('y over', this._overlap); + if (separate) { object.y = object.y - this._overlap; diff --git a/src/physics/arcade/Body.js b/src/physics/arcade/Body.js index 4e061e51..06ae389e 100644 --- a/src/physics/arcade/Body.js +++ b/src/physics/arcade/Body.js @@ -231,6 +231,7 @@ Phaser.Physics.Arcade.Body.prototype = { }, + // Basically Math.abs deltaAbsX: function () { return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX()); }, diff --git a/src/tilemap/Tilemap.js b/src/tilemap/Tilemap.js index fa695266..40eec6c8 100644 --- a/src/tilemap/Tilemap.js +++ b/src/tilemap/Tilemap.js @@ -138,6 +138,8 @@ Phaser.Tilemap.prototype.parseTiledJSON = function (json, key) { continue; } + // layer.createQuadTree(json.tilewidth * json.layers[i].width, json.tileheight * json.layers[i].height); + layer.alpha = json.layers[i].opacity; layer.visible = json.layers[i].visible; layer.tileMargin = json.tilesets[0].margin; @@ -183,8 +185,6 @@ Phaser.Tilemap.prototype.parseTiledJSON = function (json, key) { */ Phaser.Tilemap.prototype.generateTiles = function (qty) { - console.log('generating', qty, 'tiles'); - for (var i = 0; i < qty; i++) { this.tiles.push(new Phaser.Tile(this.game, this, i, this.currentLayer.tileWidth, this.currentLayer.tileHeight)); diff --git a/src/tilemap/TilemapLayer.js b/src/tilemap/TilemapLayer.js index 28f4a710..8e5487ee 100644 --- a/src/tilemap/TilemapLayer.js +++ b/src/tilemap/TilemapLayer.js @@ -87,6 +87,8 @@ Phaser.TilemapLayer = function (parent, id, key, mapFormat, name, tileWidth, til this._alpha = 1; + this.quadTree = null; + this.canvas = null; this.context = null; this.baseTexture = null; @@ -472,6 +474,12 @@ Phaser.TilemapLayer.prototype = { this.parent.addChild(this.sprite); + }, + + createQuadTree: function (width, height) { + + this.quadTree = new Phaser.QuadTree(this, 0, 0, width, height, 20, 4); + }, /** diff --git a/src/tilemap/TilemapRenderer.js b/src/tilemap/TilemapRenderer.js index dc7a4752..bd881058 100644 --- a/src/tilemap/TilemapRenderer.js +++ b/src/tilemap/TilemapRenderer.js @@ -112,8 +112,15 @@ Phaser.TilemapRenderer.prototype = { layer.tileWidth, layer.tileHeight ); + + if (tilemap.tiles[this._columnData[tile]].collideNone == false) + { + layer.context.fillStyle = 'rgba(255,255,0,0.5)'; + layer.context.fillRect(this._tx, this._ty, layer.tileWidth, layer.tileHeight); + } } + this._tx += layer.tileWidth; } diff --git a/src/utils/Debug.js b/src/utils/Debug.js index b197927e..6516684e 100644 --- a/src/utils/Debug.js +++ b/src/utils/Debug.js @@ -398,8 +398,10 @@ Phaser.Utils.Debug.prototype = { // this.line('ty: ' + sprite.worldTransform[5]); // this.line('skew x: ' + sprite.worldTransform[3]); // this.line('skew y: ' + sprite.worldTransform[1]); - // this.line('dx: ' + sprite.body.deltaX()); - // this.line('dy: ' + sprite.body.deltaY()); + this.line('dx: ' + sprite.body.deltaX()); + this.line('dy: ' + sprite.body.deltaY()); + this.line('sdx: ' + sprite.deltaX()); + this.line('sdy: ' + sprite.deltaY()); // this.line('inCamera: ' + this.game.renderer.spriteRenderer.inCamera(this.game.camera, sprite));