From 45b6d5a74146417a543e441b6fd517b33824c8f9 Mon Sep 17 00:00:00 2001 From: photonstorm Date: Fri, 31 Jan 2014 05:42:20 +0000 Subject: [PATCH] Removed: Debug.renderSpriteTouching, Debug.renderLocalTransformInfo, Debug.renderWorldTransformInfo, Debug.renderSpriteCollision and Debug.dumpLinkedList. Debug.renderPhysicsBody(body, color) is extremely useful for debugging the new physics bodies. Will draw the outline + points in the color given. Debug.renderBodyInfo(sprite, x, y, color) will display lots of Sprite body data. --- README.md | 10 +- examples/wip/rabbit map.js | 63 +++---- src/core/Game.js | 55 ++++-- src/gameobjects/Sprite.js | 14 -- src/geom/Line.js | 8 + src/physics/arcade/ArcadePhysics.js | 9 +- src/physics/arcade/Body.js | 74 ++++---- src/tilemap/Tile.js | 2 - src/tilemap/TilemapLayer.js | 202 +++------------------- src/utils/Debug.js | 256 +++------------------------- 10 files changed, 183 insertions(+), 510 deletions(-) diff --git a/README.md b/README.md index d4a74158..0f0d40df 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ Significant API changes: * Removed Body.deltaAbsX and deltaAbsY as they are no longer used internally. * Body.screenX and screenY moved to getters, no longer calculated every frame. * ArcadePhysics now has setBounds and setBoundsToWorld, and you can specify which walls are created or not (left, right, up, down) +* Removed: Debug.renderSpriteTouching, Debug.renderLocalTransformInfo, Debug.renderWorldTransformInfo, Debug.renderSpriteCollision and Debug.dumpLinkedList. New features: @@ -91,7 +92,7 @@ New features: * Group.set will let you deep set a new propery on a single child of the Group. * Stage.display property added. A direct reference to the root Pixi Stage object (very useful for RenderTexture manipulation) * Added Ejecta detection to Device (thanks endel) -* Tweens can now work with relative + and - values. You can do: `tween(sprite).to( { x: '+400' })` and it will add 400 to the current sprite.x value, or '-400'. +* Tweens can now work with relative + and - values. You can do: `tween(sprite).to( { x: '+400' })` and it will add 400 to the current sprite.x value. * Buttons now properly use their upFrame if set. * InputHandler now has snapOffsetX and snapOffsetY properties so your snap grid doesn't have to be 0,0 aligned (thanks srmeier) * Loader.progressFloat contains the actual non-rounded progress value, where-as Loader.progress contains a rounded value. Use progressFloat if you've > 100 files to load. @@ -111,12 +112,15 @@ New features: * Math.normalizeAngle - normalises an angle, now in radians only. * Math.normalizeLatitude - Normalizes a latitude to the [-90,90] range. * Math.normalizeLongitude - Normalizes a longitude to the [-180,180] range. -* Phaser.Line added to the group of geometry classes, with full point on line/segment and intersection tests (see new examples) +* Phaser.Line added to the geometry classes, with full point on line/segment and intersection tests (see new examples) * Phaser.CANVAS_PX_ROUND is a boolean. If 'true' the Canvas renderer will Math.floor() all coordinates before drawImage, stopping pixel interpolation. Defaults to false. * Phaser.CANVAS_CLEAR_RECT is a boolean. If 'true' (the default) it will context.clearRect() every frame. If false this is skipped (useful if you know you don't need it) * Collision now works between Sprites positioned via sprite.x/y, sprite.body.x/y or sprite.body.velocity. * If you are tweening a sprite and still want physics collision, set `sprite.body.moves = false` otherwise it will fight against the tween motion. - +* Game.enableStep will enable core game loop stepping. When enabled you must call game.step() directly (perhaps via a DOM button?), very useful for debugging! +* Game.disableStep turns core update loop stepping off. +* Debug.renderPhysicsBody(body, color) is extremely useful for debugging the new physics bodies. Will draw the outline + points in the color given. +* Debug.renderBodyInfo(sprite, x, y, color) will display lots of Sprite body data. New Examples: diff --git a/examples/wip/rabbit map.js b/examples/wip/rabbit map.js index 82565601..b38a8ae6 100644 --- a/examples/wip/rabbit map.js +++ b/examples/wip/rabbit map.js @@ -54,15 +54,20 @@ console.log(' --- state create start ---'); layer.resizeWorld(); - // game.physics.gravity.y = 200; + game.physics.gravity.y = 200; - sprite = game.add.sprite(100, 180, 'phaser'); - sprite.body.moves = false; + sprite = game.add.sprite(100, 240, 'phaser'); + // sprite.anchor.setTo(0.5, 0.5); + // sprite.body.setCircle(20); + + // sprite.body.moves = false; ball = game.add.sprite(200, 180, 'ball'); - game.add.tween(sprite).to({x: 500},5000,Phaser.Easing.Linear.None,true); + // game.add.tween(sprite).to({x: 500},5000,Phaser.Easing.Linear.None,true); + + // game.add.tween(sprite).to({angle: 360},5000,Phaser.Easing.Linear.None,true); // sprite = game.add.sprite(200, 240, 'phaser'); // 3-block corner test @@ -74,7 +79,9 @@ console.log(' --- state create start ---'); // sprite.body.velocity.y = 200; - // sprite.anchor.setTo(0.5, 0.5); + + + // We'll set a lower max angular velocity here to keep it from going totally nuts // sprite.body.maxAngular = 500; @@ -83,7 +90,7 @@ console.log(' --- state create start ---'); // sprite.body.angularDrag = 50; // sprite.body.bounce.x = 0.8; - // sprite.body.bounce.y = 0.8; + sprite.body.bounce.y = 0.8; // sprite.angle = 35; @@ -124,6 +131,10 @@ function update() { // sprite.body.velocity.y = -300; + // sprite.body.angularVelocity = -100; + // sprite.body.angularAcceleration = 200; + + // sprite.body.velocity.x = 0; // sprite.body.velocity.y = 0; // sprite.body.angularVelocity = 0; @@ -131,7 +142,6 @@ function update() { // sprite.body.acceleration.x = 0; // sprite.body.angularAcceleration = 0; - /* if (cursors.left.isDown) { // sprite.body.acceleration.x = -200; @@ -149,11 +159,6 @@ function update() { { game.physics.velocityFromAngle(sprite.angle, 300, sprite.body.velocity); } - else - { - // game.physics.velocityFromAngle(sprite.angle, sprite.body.velocity, sprite.body.velocity); - } - */ @@ -201,23 +206,23 @@ function update() { // sprite.x += 2; // } - if (cursors.up.isDown) - { - sprite.body.y -= 2; - } - else if (cursors.down.isDown) - { - sprite.body.y += 2; - } + // if (cursors.up.isDown) + // { + // sprite.body.y -= 2; + // } + // else if (cursors.down.isDown) + // { + // sprite.body.y += 2; + // } - if (cursors.left.isDown) - { - sprite.body.x -= 2; - } - else if (cursors.right.isDown) - { - sprite.body.x += 2; - } + // if (cursors.left.isDown) + // { + // sprite.body.x -= 2; + // } + // else if (cursors.right.isDown) + // { + // sprite.body.x += 2; + // } @@ -228,7 +233,7 @@ function render() { // game.debug.renderSpriteBody(sprite); // game.debug.renderSpriteBounds(sprite); - // game.debug.renderPhysicsBody(sprite.body); + game.debug.renderPhysicsBody(sprite.body); game.debug.renderBodyInfo(sprite, 32, 32); // game.debug.renderLine(marker, 'rgba(255,255,255,0.5)'); diff --git a/src/core/Game.js b/src/core/Game.js index 6e6aafd4..240503a8 100644 --- a/src/core/Game.js +++ b/src/core/Game.js @@ -226,6 +226,27 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant */ this.particles = null; + /** + * @property {boolean} stepping - Enable core loop stepping with Game.enableStep(). + * @default + * @readonly + */ + this.stepping = false; + + /** + * @property {boolean} stepping - An internal property used by enableStep, but also useful to query from your own game objects. + * @default + * @readonly + */ + this.pendingStep = false; + + /** + * @property {number} stepCount - When stepping is enabled this contains the current step cycle. + * @default + * @readonly + */ + this.stepCount = 0; + // Parse the configuration object (if any) if (arguments.length === 1 && typeof arguments[0] === 'object') { @@ -283,10 +304,6 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant window.addEventListener('load', this._onBoot, false); } - this.pendingStep = false; - this.stepping = false; - this.stepCount = 0; - return this; }; @@ -592,21 +609,17 @@ Phaser.Game.prototype = { } this.plugins.preUpdate(); - // console.log('world preUpdate'); this.world.preUpdate(); this.stage.update(); this.input.update(); this.tweens.update(); this.sound.update(); - // console.log('state update'); this.state.update(); - // console.log('world update'); this.world.update(); this.particles.update(); this.plugins.update(); - // console.log('world postUpdate'); this.world.postUpdate(); this.plugins.postUpdate(); } @@ -623,6 +636,12 @@ Phaser.Game.prototype = { }, + /** + * Enable core game loop stepping. When enabled you must call game.step() directly (perhaps via a DOM button?) + * Calling step will advance the game loop by one frame. This is extremely useful to hard to track down errors! + * + * @method Phaser.Game#enableStep + */ enableStep: function () { this.stepping = true; @@ -631,12 +650,28 @@ Phaser.Game.prototype = { }, + /** + * Disables core game loop stepping. + * + * @method Phaser.Game#disableStep + */ + disableStep: function () { + + this.stepping = false; + this.pendingStep = false; + + }, + + /** + * When stepping is enabled you must call this function directly (perhaps via a DOM button?) to advance the game loop by one frame. + * This is extremely useful to hard to track down errors! Use the internal stepCount property to monitor progress. + * + * @method Phaser.Game#step + */ step: function () { this.pendingStep = false; this.stepCount++; - console.log(''); - console.log('----------------------------- Game step', this.stepCount); }, diff --git a/src/gameobjects/Sprite.js b/src/gameobjects/Sprite.js index aac2902d..7a3fd1fa 100644 --- a/src/gameobjects/Sprite.js +++ b/src/gameobjects/Sprite.js @@ -373,13 +373,10 @@ Phaser.Sprite = function (game, x, y, key, frame) { this.updateCache(); this.updateBounds(); - this.debug = false; - /** * @property {PIXI.Point} pivot - The pivot point of the displayObject that it rotates around. */ - }; // Needed to keep the PIXI.Sprite constructor in the prototype chain (as the core pixi renderer uses an instanceof check sadly) @@ -394,11 +391,6 @@ Phaser.Sprite.prototype.constructor = Phaser.Sprite; */ Phaser.Sprite.prototype.preUpdate = function() { -if (this.debug) -{ - console.log('Sprite preUpdate xy: ', this.x, this.y, 'wxy:', this.world.x, this.world.y); -} - if (!this.exists || (this.group && !this.group.exists)) { this.renderOrderID = -1; @@ -706,12 +698,6 @@ Phaser.Sprite.prototype.postUpdate = function() { this.position.x = this._cache.x; this.position.y = this._cache.y; - -if (this.debug) -{ - console.log('Sprite postUpdate xy: ', this.x, this.y, 'right:', this.right); -} - } }; diff --git a/src/geom/Line.js b/src/geom/Line.js index fe4d6fc8..97ed8b18 100644 --- a/src/geom/Line.js +++ b/src/geom/Line.js @@ -54,6 +54,14 @@ Phaser.Line.prototype = { }, + /** + * Sets the line to match the x/y coordinates of the two given sprites. + * Can optionally be calculated from their center coordinates. + * @method Phaser.Line#fromSprite + * @param {Phaser.Sprite} startSprite - The coordinates of this Sprite will be set to the Line.start point. + * @param {Phaser.Sprite} endSprite - The coordinates of this Sprite will be set to the Line.start point. + * @param {boolean} [useCenter=true] - If true it will use startSprite.center.x, if false startSprite.x. + */ fromSprite: function (startSprite, endSprite, useCenter) { if (typeof useCenter === 'undefined') { useCenter = true; } diff --git a/src/physics/arcade/ArcadePhysics.js b/src/physics/arcade/ArcadePhysics.js index 57787580..4ff698e5 100644 --- a/src/physics/arcade/ArcadePhysics.js +++ b/src/physics/arcade/ArcadePhysics.js @@ -99,6 +99,12 @@ Phaser.Physics.Arcade = function (game) { */ this._angle = 0; + /** + * @property {number} _drag - Internal cache var. + * @private + */ + this._drag = 0; + /** * @property {number} _dx - Internal cache var. * @private @@ -376,7 +382,8 @@ Phaser.Physics.Arcade.prototype = { if (body.sprite.debug) { - console.log('updateMotion: acx', body.acceleration.x, 'acy', body.acceleration.y, 'gravx', this._gravityX, 'gravy', this._gravityY, 'elapsed', this.game.time.physicsElapsed); + // console.log('updateMotion: acx', body.acceleration.x, 'acy', body.acceleration.y, 'gravx', this._gravityX, 'gravy', this._gravityY, 'elapsed', this.game.time.physicsElapsed); + console.log('updateMotion: rotation', body.rotation, 'vd', this._velocityDelta, 'drag', this._drag, 'acceleration', body.angularAcceleration); } this._p.setTo((body.acceleration.x + this._gravityX) * this.game.time.physicsElapsed, (body.acceleration.y + this._gravityY) * this.game.time.physicsElapsed); diff --git a/src/physics/arcade/Body.js b/src/physics/arcade/Body.js index d8781d95..119e670f 100644 --- a/src/physics/arcade/Body.js +++ b/src/physics/arcade/Body.js @@ -447,26 +447,21 @@ Phaser.Physics.Arcade.Body.prototype = { this.preX = this.x; this.preY = this.y; - this.preRotation = this.rotation; + this.preRotation = this.sprite.angle; - this.x = this.sprite.world.x + this.offset.x; - this.y = this.sprite.world.y + this.offset.y; + // this.x = this.sprite.world.x + this.offset.x; + // this.y = this.sprite.world.y + this.offset.y; - if (this.allowRotation) - { - this.rotation = this.sprite.rotation; - - if (this.type !== Phaser.Physics.Arcade.CIRCLE && this.deltaZ() !== 0) - { - this.polygon.rotate(this.deltaZ()); - } - } + this.x = (this.sprite.world.x - (this.sprite.anchor.x * this.sprite.width)) + this.offset.x; + this.y = (this.sprite.world.y - (this.sprite.anchor.y * this.sprite.height)) + this.offset.y; + this.rotation = this.preRotation; if (this.sprite.debug) { - console.log('Body preUpdate x:', this.x, 'y:', this.y, 'left:', this.left, 'right:', this.right, 'WAS', this.preX, this.preY); - console.log('Body preUpdate blocked:', this.blocked, this.blockFlags); - console.log('Body preUpdate velocity:', this.velocity.x, this.velocity.y); + // console.log('Body preUpdate x:', this.x, 'y:', this.y, 'left:', this.left, 'right:', this.right, 'WAS', this.preX, this.preY); + // console.log('Body preUpdate blocked:', this.blocked, this.blockFlags); + // console.log('Body preUpdate velocity:', this.velocity.x, this.velocity.y); + console.log('Body preUpdate rotation:', this.rotation, this.preRotation); } this.checkBlocked(); @@ -613,8 +608,8 @@ if (this.sprite.debug) if (this.sprite.debug) { - console.log('reboundCheck start', this.velocity.x, this.velocity.y); - console.log('reBound blocked state', this.blocked); + // console.log('reboundCheck start', this.velocity.x, this.velocity.y); + // console.log('reBound blocked state', this.blocked); } if (x) @@ -626,7 +621,7 @@ if (this.sprite.debug) if (this.sprite.debug) { - console.log('X rebound applied'); + // console.log('X rebound applied'); } } @@ -640,14 +635,14 @@ if (this.sprite.debug) if (this.sprite.debug) { - console.log('reboundCheck X zeroed'); + // console.log('reboundCheck X zeroed'); } } } if (this.sprite.debug) { - console.log('reboundCheck X', this.velocity.x, 'gravity', gx); + // console.log('reboundCheck X', this.velocity.x, 'gravity', gx); } } @@ -660,7 +655,7 @@ if (this.sprite.debug) if (this.sprite.debug) { - console.log('Y rebound applied'); + // console.log('Y rebound applied'); } } @@ -674,14 +669,14 @@ if (this.sprite.debug) if (this.sprite.debug) { - console.log('reboundCheck Y zeroed'); + // console.log('reboundCheck Y zeroed'); } } } if (this.sprite.debug) { - console.log('reboundCheck Y', this.velocity.y, 'gravity', gy); + // console.log('reboundCheck Y', this.velocity.y, 'gravity', gy); } } @@ -1181,7 +1176,7 @@ if (this.sprite.debug) if (this.sprite.debug) { - console.log('integrateVelocity TEMP:', this._temp.x, this._temp.y); + // console.log('integrateVelocity TEMP:', this._temp.x, this._temp.y); } // positive = RIGHT / DOWN @@ -1193,14 +1188,14 @@ if (this.sprite.debug) this.velocity.x += this._temp.x; if (this.sprite.debug) { - console.log('integrateVelocity x added', this._dx, this.x); + // console.log('integrateVelocity x added', this._dx, this.x); } } else { if (this.sprite.debug) { - console.log('integrateVelocity x failed or zero, blocked left/right', this._dx); + // console.log('integrateVelocity x failed or zero, blocked left/right', this._dx); } } @@ -1210,14 +1205,14 @@ if (this.sprite.debug) this.velocity.y += this._temp.y; if (this.sprite.debug) { - console.log('integrateVelocity y added', this._dy, this.y); + // console.log('integrateVelocity y added', this._dy, this.y); } } else { if (this.sprite.debug) { - console.log('integrateVelocity y failed or zero, blocked up/down', this._dy); + // console.log('integrateVelocity y failed or zero, blocked up/down', this._dy); } } @@ -1275,22 +1270,29 @@ if (this.sprite.debug) if (this.sprite.debug) { - console.log('Body postUpdate x:', this.x, 'y:', this.y, 'left:', this.left, 'right:', this.right, 'WAS', this.preX, this.preY); - console.log('Body postUpdate blocked:', this.blocked, this.blockFlags); - console.log('Body postUpdate velocity:', this.velocity.x, this.velocity.y); - console.log('Body postUpdate Sprite:', this.sprite.x, this.sprite.y, 'cached', this.sprite._cache.x, this.sprite._cache.y); + // console.log('Body postUpdate x:', this.x, 'y:', this.y, 'left:', this.left, 'right:', this.right, 'WAS', this.preX, this.preY); + // console.log('Body postUpdate blocked:', this.blocked, this.blockFlags); + // console.log('Body postUpdate velocity:', this.velocity.x, this.velocity.y); + // console.log('Body postUpdate Sprite:', this.sprite.x, this.sprite.y, 'cached', this.sprite._cache.x, this.sprite._cache.y); + console.log('Body postUpdate Rotation:', this.rotation); } if (this.deltaX() !== 0 || this.deltaY() !== 0) { - this.sprite.worldTransform[2] = this.sprite.x = (this.x - this.offset.x); - this.sprite.worldTransform[5] = this.sprite.y = (this.y - this.offset.y); + // this.sprite.worldTransform[2] = this.sprite.x = (this.x - this.offset.x); + // this.sprite.worldTransform[5] = this.sprite.y = (this.y - this.offset.y); + + this.sprite.worldTransform[2] = this.sprite.x = (this.x + (this.sprite.anchor.x * this.sprite.width) - this.offset.x); + this.sprite.worldTransform[5] = this.sprite.y = (this.y + (this.sprite.anchor.y * this.sprite.height) - this.offset.y); + + // this.x = (this.sprite.world.x - (this.sprite.anchor.x * this.width)) + this.offset.x; + // this.y = (this.sprite.world.y - (this.sprite.anchor.y * this.height)) + this.offset.y; } - if (this.allowRotation) + if (this.allowRotation && this.deltaZ() !== 0) { // this.sprite.rotation = this.rotation; - // this.sprite.angle += this.deltaZ(); + this.sprite.angle += this.deltaZ(); // this.sprite.angle = this.angle; } diff --git a/src/tilemap/Tile.js b/src/tilemap/Tile.js index 6acaa287..bf2a8f49 100644 --- a/src/tilemap/Tile.js +++ b/src/tilemap/Tile.js @@ -131,8 +131,6 @@ Phaser.Tile = function (layer, index, x, y, width, height) { */ this.callbackContext = this; - this.debug = false; - }; Phaser.Tile.prototype = { diff --git a/src/tilemap/TilemapLayer.js b/src/tilemap/TilemapLayer.js index 66e4dff8..1a667379 100644 --- a/src/tilemap/TilemapLayer.js +++ b/src/tilemap/TilemapLayer.js @@ -482,193 +482,36 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides height = this.layer.heightInPixels; } - // console.log('getTiles', x, y, width, height, collides); - // Convert the pixel values into tile coordinates this._tx = this.game.math.snapToFloor(x, this._cw) / this._cw; this._ty = this.game.math.snapToFloor(y, this._ch) / this._ch; this._tw = (this.game.math.snapToCeil(width, this._cw) + this._cw) / this._cw; this._th = (this.game.math.snapToCeil(height, this._ch) + this._ch) / this._ch; - // console.log('getTiles snapped', this._tx, this._ty, this._tw, this._th); - // This should apply the layer x/y here this._results.length = 0; - // var _tile = null; - // this.context.fillStyle = 'rgba(255,0,0,0.3)'; - // this.context.fillRect(this._tx * this._cw, this._ty * this._ch, this._tw * this._cw, this._th * this._ch); - for (var wy = this._ty; wy < this._ty + this._th; wy++) { for (var wx = this._tx; wx < this._tx + this._tw; wx++) { if (this.layer.data[wy] && this.layer.data[wy][wx]) { - // _tile = this.layer.data[wy][wx]; - - // if (_tile && (collides === false || (collides && _tile.collides)) - // { - if (collides === false || (collides && this.layer.data[wy][wx].canCollide)) - { - // Convert tile coordinates back to camera space for return - var _wx = this._unfixX(wx * this._cw) / this._cw; - var _wy = this._unfixY(wy * this._ch) / this._ch; - - this._results.push({ - x: _wx * this._cw, - y: _wy * this._ch, - right: (_wx * this._cw) + this._cw, - bottom: (_wy * this._ch) + this._ch, - tile: this.layer.data[wy][wx], - layer: this.layer.data[wy][wx].layer - }); - - } - // } - } - } - } - - // console.log('getTiles results', this._results); - - return this._results; - -} - -/** -* Get all tiles that exist within the given area, defined by the top-left corner, width and height. Values given are in pixels, not tiles. -* This function also draws to the context all of the debug areas. -* @method Phaser.TilemapLayer#debugGetTiles -* @memberof Phaser.TilemapLayer -* @param {number} x - X position of the top left corner. -* @param {number} y - Y position of the top left corner. -* @param {number} width - Width of the area to get. -* @param {number} height - Height of the area to get. -* @param {boolean} [collides=false] - If true only return tiles that collide on one or more faces. -* @return {array} Array with tiles informations (each contains x, y, and the tile). -Phaser.TilemapLayer.prototype.debugGetTiles = function (x, y, width, height, collides) { - - if (this.tilemap === null) - { - return; - } - - // Should we only get tiles that have at least one of their collision flags set? (true = yes, false = no just get them all) - if (typeof collides === 'undefined') { collides = false; } - if (typeof debug === 'undefined') { debug = false; } - - // adjust the x,y coordinates for scrollFactor - x = this._fixX(x); - y = this._fixY(y); - - if (width > this.widthInPixels) - { - width = this.widthInPixels; - } - - if (height > this.heightInPixels) - { - height = this.heightInPixels; - } - - if (debug) - { - console.log('x', x, 'y', y, 'w', width, 'h', height); - } - - // this.context.fillStyle = 'rgba(255,0,255,0.5)'; - // this.context.fillRect(x, y, width, height); - - var tileWidth = this.tileWidth * this.scale.x; - var tileHeight = this.tileHeight * this.scale.y; - - // Convert the pixel values into tile coordinates - this._tx = this.game.math.snapToFloor(x, tileWidth) / tileWidth; - this._ty = this.game.math.snapToFloor(y, tileHeight) / tileHeight; - this._tw = (this.game.math.snapToCeil(width, tileWidth) + tileWidth) / tileWidth; - this._th = (this.game.math.snapToCeil(height, tileHeight) + tileHeight) / tileHeight; - - if (debug) - { - console.log('tx', this._tx, 'ty', this._ty, 'tw', this._tw, 'th', this._th); - } - - // this.context.fillRect(this._tx * tileWidth, this._ty * tileHeight, this._tw * tileWidth, this._th * tileHeight); - - // This should apply the layer x/y here - this._results.length = 0; - - var _index = 0; - var _tile = null; - var sx = 0; - var sy = 0; - - this.context.fillStyle = 'rgba(255,0,0,1)'; - // this.context.strokeStyle = 'rgba(0,0,0,1)'; - - for (var wy = this._ty; wy < this._ty + this._th; wy++) - { - if (debug) - { - console.log('wy', wy); - } - - for (var wx = this._tx; wx < this._tx + this._tw; wx++) - { - if (debug) - { - console.log('wx', wx); - } - - if (this.layer.data[wy] && this.layer.data[wy][wx]) - { - // Could combine - // _index = this.layer.data[wy][wx] - 1; - // _tile = this.tileset.getTile(_index); - _tile = this.layer.data[wy][wx]; - - if (debug) + if (collides === false || (collides && this.layer.data[wy][wx].canCollide)) { - console.log('tile', _tile); + // Convert tile coordinates back to camera space for return + var _wx = this._unfixX(wx * this._cw) / this._cw; + var _wy = this._unfixY(wy * this._ch) / this._ch; + + this._results.push({ + x: _wx * this._cw, + y: _wy * this._ch, + right: (_wx * this._cw) + this._cw, + bottom: (_wy * this._ch) + this._ch, + tile: this.layer.data[wy][wx], + layer: this.layer.data[wy][wx].layer + }); } - - if (_tile) - { - - // sx = _tile.width * this.scale.x; - // sy = _tile.height * this.scale.y; - sx = this.tileWidth * this.scale.x; - sy = this.tileHeight * this.scale.y; - - if (collides === false || (collides && _tile.collides)) - { - if (debug) - { - this.context.fillRect(_tile.x * this.tileWidth, _tile.y * this.tileHeight, this.tileWidth, this.tileHeight); - } - - // this.context.strokeRect(_tile.x * this.tileWidth, _tile.y * this.tileHeight, this.tileWidth, this.tileHeight); - - // convert tile coordinates back to camera space for return - var _wx = this._unfixX(wx * sx) / this.tileWidth; - var _wy = this._unfixY(wy * sy) / this.tileHeight; - - this._results.push({ - x: _wx * sx, - y: _wy * sy, - width: sx, - height: sy, - right: (_wx * sx) + sx, - bottom: (_wy * sy) + sy, - tx: _wx, - ty: _wy, - tile: _tile - }); - } - - } - } } } @@ -676,7 +519,6 @@ Phaser.TilemapLayer.prototype.debugGetTiles = function (x, y, width, height, col return this._results; } -*/ /** * Internal function to update maximum values. @@ -703,8 +545,6 @@ Phaser.TilemapLayer.prototype.updateMax = function () { this.dirty = true; - // console.log('updateMax', this._maxX, this._maxY, 'px', this.layer.widthInPixels, this.layer.heightInPixels, 'rwh', this.layer.width, this.layer.height); - } /** @@ -714,15 +554,15 @@ Phaser.TilemapLayer.prototype.updateMax = function () { */ Phaser.TilemapLayer.prototype.render = function () { - // if (this.layer.dirty) - // { - // this.dirty = true; - // } + if (this.layer.dirty) + { + this.dirty = true; + } - // if (!this.dirty || !this.visible) - // { - // return; - // } + if (!this.dirty || !this.visible) + { + return; + } this._prevX = this._dx; this._prevY = this._dy; diff --git a/src/utils/Debug.js b/src/utils/Debug.js index 09a0d4c9..bb5f29b9 100644 --- a/src/utils/Debug.js +++ b/src/utils/Debug.js @@ -418,29 +418,6 @@ Phaser.Utils.Debug.prototype = { }, - /** - * Render Sprite collision. - * @method Phaser.Utils.Debug#renderSpriteCollision - * @param {Phaser.Sprite} sprite - The sprite to be rendered. - * @param {number} x - X position of the debug info to be rendered. - * @param {number} y - Y position of the debug info to be rendered. - * @param {string} [color='rgb(255,255,255)'] - color of the debug info to be rendered. (format is css color string). - */ - renderSpriteCollision: function (sprite, x, y, color) { - - color = color || 'rgb(255,255,255)'; - - this.start(x, y, color, 100); - - this.line('Body: (width: ' + sprite.width + ' height: ' + sprite.height + ')'); - this.line('left: ' + sprite.body.touching.left); - this.line('right: ' + sprite.body.touching.right); - this.line('up: ' + sprite.body.touching.up); - this.line('down: ' + sprite.body.touching.down); - this.stop(); - - }, - /** * Render Sprite Body Physics Data as text. * @method Phaser.Utils.Debug#renderBodyInfo @@ -541,65 +518,13 @@ Phaser.Utils.Debug.prototype = { }, /** - * Render the World Transform information of the given Sprite. - * @method Phaser.Utils.Debug#renderWorldTransformInfo - * @param {Phaser.Sprite} sprite - Description. + * Renders the sprite coordinates in local, positional and world space. + * @method Phaser.Utils.Debug#renderSpriteCoords + * @param {Phaser.Sprite} line - The sprite to inspect. * @param {number} x - X position of the debug info to be rendered. * @param {number} y - Y position of the debug info to be rendered. * @param {string} [color='rgb(255,255,255)'] - color of the debug info to be rendered. (format is css color string). */ - renderWorldTransformInfo: function (sprite, x, y, color) { - - if (this.context == null) - { - return; - } - - color = color || 'rgb(255, 255, 255)'; - - this.start(x, y, color); - - this.line('World Transform'); - this.line('skewX: ' + sprite.worldTransform[3]); - this.line('skewY: ' + sprite.worldTransform[1]); - this.line('scaleX: ' + sprite.worldTransform[0]); - this.line('scaleY: ' + sprite.worldTransform[4]); - this.line('transX: ' + sprite.worldTransform[2]); - this.line('transY: ' + sprite.worldTransform[5]); - this.stop(); - - }, - - /** - * Render the Local Transform information of the given Sprite. - * @method Phaser.Utils.Debug#renderLocalTransformInfo - * @param {Phaser.Sprite} sprite - Description. - * @param {number} x - X position of the debug info to be rendered. - * @param {number} y - Y position of the debug info to be rendered. - * @param {string} [color='rgb(255,255,255)'] - color of the debug info to be rendered. (format is css color string). - */ - renderLocalTransformInfo: function (sprite, x, y, color) { - - if (this.context == null) - { - return; - } - - color = color || 'rgb(255, 255, 255)'; - - this.start(x, y, color); - - this.line('Local Transform'); - this.line('skewX: ' + sprite.localTransform[3]); - this.line('skewY: ' + sprite.localTransform[1]); - this.line('scaleX: ' + sprite.localTransform[0]); - this.line('scaleY: ' + sprite.localTransform[4]); - this.line('transX: ' + sprite.localTransform[2]); - this.line('transY: ' + sprite.localTransform[5]); - this.stop(); - - }, - renderSpriteCoords: function (sprite, x, y, color) { if (this.context == null) @@ -698,62 +623,6 @@ Phaser.Utils.Debug.prototype = { }, - /** - * Renders just the Sprite.body bounds. - * @method Phaser.Utils.Debug#renderSpriteBody - * @param {Phaser.Sprite} sprite - Description. - * @param {string} [color] - Color of the debug info to be rendered (format is css color string). - */ - renderSpriteTouching: function (sprite, color) { - - if (this.context == null || sprite.body.touching.none === true) - { - return; - } - - color = color || 'rgba(255,0,255, 0.3)'; - - this.start(0, 0, color); - - this.context.fillStyle = color; - this.context.fillRect(sprite.body.screenX, sprite.body.screenY, sprite.body.width, sprite.body.height); - - this.stop(); - this.start(0, 0, color); - - this.context.beginPath(); - this.context.strokeStyle = '#000000'; - - if (sprite.body.touching.up) - { - this.context.moveTo(sprite.body.x, sprite.body.y); - this.context.lineTo(sprite.body.x + sprite.body.width, sprite.body.y); - } - - if (sprite.body.touching.down) - { - this.context.moveTo(sprite.body.x, sprite.body.y + sprite.body.height); - this.context.lineTo(sprite.body.x + sprite.body.width, sprite.body.y + sprite.body.height); - } - - if (sprite.body.touching.left) - { - this.context.moveTo(sprite.body.x, sprite.body.y); - this.context.lineTo(sprite.body.x, sprite.body.y + sprite.body.height); - } - - if (sprite.body.touching.right) - { - this.context.moveTo(sprite.body.x + sprite.body.width, sprite.body.y); - this.context.lineTo(sprite.body.x + sprite.body.width, sprite.body.y + sprite.body.height); - } - - this.context.stroke(); - - this.stop(); - - }, - /** * Renders just the full Sprite bounds. * @method Phaser.Utils.Debug#renderSpriteBounds @@ -777,12 +646,12 @@ Phaser.Utils.Debug.prototype = { if (fill) { this.context.fillStyle = color; - this.context.fillRect(sprite.bounds.x, sprite.bounds.y, sprite.bounds.width, sprite.bounds.height); + this.context.fillRect(sprite.body.left, sprite.body.top, sprite.body.width, sprite.body.height); } else { this.context.strokeStyle = color; - this.context.strokeRect(sprite.body.x, sprite.body.y, sprite.body.width, sprite.body.height); + this.context.strokeRect(sprite.body.left, sprite.body.top, sprite.body.width, sprite.body.height); this.context.stroke(); } @@ -982,37 +851,35 @@ Phaser.Utils.Debug.prototype = { this.start(0, 0, color); - // this.context.beginPath(); - // this.context.moveTo(x + points[0].x, y + points[0].y); + this.context.beginPath(); + this.context.moveTo(x + points[0].x, y + points[0].y); - // for (var i = 1; i < points.length; i++) - // { - // this.context.lineTo(x + points[i].x, y + points[i].y); - // } + for (var i = 1; i < points.length; i++) + { + this.context.lineTo(x + points[i].x, y + points[i].y); + } - // this.context.closePath(); - // this.context.strokeStyle = color; - // this.context.stroke(); + this.context.closePath(); + this.context.strokeStyle = color; + this.context.stroke(); - // this.context.fillStyle = 'rgb(255,0,0)'; - // this.context.fillRect(x + points[0].x - 2, y + points[0].y - 2, 5, 5); + this.context.fillStyle = 'rgb(255,0,0)'; + this.context.fillRect(x + points[0].x - 2, y + points[0].y - 2, 5, 5); - // for (var i = 1; i < points.length; i++) - // { - // this.context.fillRect(x + points[i].x - 2, y + points[i].y - 2, 5, 5); - // } + for (var i = 1; i < points.length; i++) + { + this.context.fillRect(x + points[i].x - 2, y + points[i].y - 2, 5, 5); + } - this.context.strokeStyle = 'rgb(0,255,255)'; - this.context.strokeRect(body.left, body.top, body.width, body.height); + // this.context.strokeStyle = 'rgb(0,255,255)'; + // this.context.strokeRect(body.left, body.top, body.width, body.height); this.stop(); } }, - /** - * * @method Phaser.Utils.Debug#renderPolygon * @param {array} polygon * @param {string} [color='rgb(255,255,255)'] - The color the polygon is stroked in. @@ -1046,85 +913,6 @@ Phaser.Utils.Debug.prototype = { this.stop(); - }, - - /** - * Dumps the Linked List to the console. - * - * @method Phaser.Utils.Debug#Phaser.LinkedList#dump - * @param {Phaser.LinkedList} list - The LinkedList to dump. - */ - dumpLinkedList: function (list) { - - var spacing = 20; - - var output = "\n" + Phaser.Utils.pad('Node', spacing) + "|" + Phaser.Utils.pad('Next', spacing) + "|" + Phaser.Utils.pad('Previous', spacing) + "|" + Phaser.Utils.pad('First', spacing) + "|" + Phaser.Utils.pad('Last', spacing); - console.log(output); - - var output = Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing); - console.log(output); - - var entity = list; - - var testObject = entity.last.next; - entity = entity.first; - - do - { - var name = entity.sprite.name || '*'; - var nameNext = '-'; - var namePrev = '-'; - var nameFirst = '-'; - var nameLast = '-'; - - if (entity.next) - { - nameNext = entity.next.sprite.name; - } - - if (entity.prev) - { - namePrev = entity.prev.sprite.name; - } - - if (entity.first) - { - nameFirst = entity.first.sprite.name; - } - - if (entity.last) - { - nameLast = entity.last.sprite.name; - } - - if (typeof nameNext === 'undefined') - { - nameNext = '-'; - } - - if (typeof namePrev === 'undefined') - { - namePrev = '-'; - } - - if (typeof nameFirst === 'undefined') - { - nameFirst = '-'; - } - - if (typeof nameLast === 'undefined') - { - nameLast = '-'; - } - - var output = Phaser.Utils.pad(name, spacing) + "|" + Phaser.Utils.pad(nameNext, spacing) + "|" + Phaser.Utils.pad(namePrev, spacing) + "|" + Phaser.Utils.pad(nameFirst, spacing) + "|" + Phaser.Utils.pad(nameLast, spacing); - console.log(output); - - entity = entity.next; - - } - while(entity != testObject) - } };