diff --git a/README.md b/README.md index 3055d140e..368c0e832 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,10 @@ Version 1.0.7 (in progress in the dev branch) * Added Sprite.destroy back in again and made it a lot more robust at cleaning up child objects. * Added 'return this' to all the core Loader functions so you can chain load calls if you so wish. * Group.alpha is now exposed publically and changes the Group container object (not the children directly, who can still have their own alpha values) +* Device.webGL uses new inspection code to accurately catch more webGL capable devices. +* Fixed an issue where creating an animation with just one frame with an index of zero would cause a UUID error (thanks SYNYST3R1) +* Fixed Rectangle.union (thanks andron77) +* Debug.renderSpriteBody updated to use a the new Sprite.Body.screenX/Y properties. diff --git a/build/phaser.js b/build/phaser.js index 952797f53..5a690b173 100644 --- a/build/phaser.js +++ b/build/phaser.js @@ -9,7 +9,7 @@ * * Phaser - http://www.phaser.io * -* v1.0.7 - Built at: Mon, 14 Oct 2013 15:29:30 +0100 +* v1.0.7 - Built at: Tue, 15 Oct 2013 21:10:11 +0100 * * By Richard Davey http://www.photonstorm.com @photonstorm * @@ -12676,8 +12676,21 @@ Phaser.Keyboard.prototype = { this._hotkeys[event.keyCode].processKeyUp(event); } - this._keys[event.keyCode].isDown = false; - this._keys[event.keyCode].timeUp = this.game.time.now; + if (this._keys[event.keyCode]) + { + this._keys[event.keyCode].isDown = false; + this._keys[event.keyCode].timeUp = this.game.time.now; + } + else + { + // Not used this key before, so register it + this._keys[event.keyCode] = { + isDown: false, + timeDown: this.game.time.now, + timeUp: this.game.time.now, + duration: 0 + }; + } }, @@ -22244,14 +22257,16 @@ Phaser.Rectangle.intersection = function (a, b, out) { * @method Phaser.Rectangle.intersects * @param {Phaser.Rectangle} a - The first Rectangle object. * @param {Phaser.Rectangle} b - The second Rectangle object. -* @param {number} tolerance - A tolerance value to allow for an intersection test with padding, default to 0 * @return {boolean} A value of true if the specified object intersects with this Rectangle object; otherwise false. */ -Phaser.Rectangle.intersects = function (a, b, tolerance) { +Phaser.Rectangle.intersects = function (a, b) { - tolerance = tolerance || 0; + return (a.x < b.right && b.x < a.right && a.y < b.bottom && b.y < a.bottom); - return !(a.x > b.right + tolerance || a.right < b.x - tolerance || a.y > b.bottom + tolerance || a.bottom < b.y - tolerance); + // return (a.x <= b.right && b.x <= a.right && a.y <= b.bottom && b.y <= a.bottom); + + // return (a.left <= b.right && b.left <= a.right && a.top <= b.bottom && b.top <= a.bottom); + // return !(a.x > b.right + tolerance || a.right < b.x - tolerance || a.y > b.bottom + tolerance || a.bottom < b.y - tolerance); }; @@ -28982,17 +28997,14 @@ Phaser.Utils.Debug.prototype = { return; } - x = x || null; - y = y || null; + if (typeof x !== 'number') { x = 0; } + if (typeof y !== 'number') { y = 0; } + color = color || 'rgb(255,255,255)'; - if (x && y) - { - this.currentX = x; - this.currentY = y; - this.currentColor = color; - } - + this.currentX = x; + this.currentY = y; + this.currentColor = color; this.currentAlpha = this.context.globalAlpha; this.context.save(); @@ -29009,6 +29021,7 @@ Phaser.Utils.Debug.prototype = { */ stop: function () { + this.context.restore(); this.context.globalAlpha = this.currentAlpha; @@ -29366,7 +29379,6 @@ Phaser.Utils.Debug.prototype = { this.line('angle: ' + sprite.angle.toFixed(1) + ' rotation: ' + sprite.rotation.toFixed(1)); this.line('visible: ' + sprite.visible + ' in camera: ' + sprite.inCamera); this.line('body x: ' + sprite.body.x.toFixed(1) + ' y: ' + sprite.body.y.toFixed(1)); - this.stop(); // 0 = scaleX // 1 = skewY @@ -29382,12 +29394,13 @@ 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('deltaX: ' + sprite.body.deltaX()); + this.line('deltaY: ' + 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)); + this.stop(); }, @@ -30741,10 +30754,28 @@ Phaser.Physics.Arcade.prototype = { * @param object2 The second GameObject to separate * @returns {boolean} Returns true if the objects were separated, otherwise false. */ - separateTile: function (object, x, y, width, height, mass, collideLeft, collideRight, collideUp, collideDown, separateX, separateY) { + separateTile: function (body, tile) { - var separatedX = this.separateTileX(object.body, x, y, width, height, mass, collideLeft, collideRight, separateX); - var separatedY = this.separateTileY(object.body, x, y, width, height, mass, collideUp, collideDown, separateY); + var separatedX = this.separateTileX(body, tile, true); + var separatedY = this.separateTileY(body, tile, true); + + /* + if (separatedX) + { + console.log('x overlap', this._overlap); + } + + + if (separatedY) + { + console.log('y overlap', this._overlap); + } + + if (separatedX || separatedY) + { + return true; + } + */ if (separatedX || separatedY) { @@ -30761,59 +30792,53 @@ Phaser.Physics.Arcade.prototype = { * @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) { + separateTileX: function (body, tile, separate) { // Can't separate two immovable objects (tiles are always immovable) - if (object.immovable) + if (body.immovable || body.deltaX() == 0 || Phaser.Rectangle.intersects(body.hullX, tile) == false) { return false; } - // First, get the object delta this._overlap = 0; - // console.log('separatedX', x, y, object.deltaX()); + // The hulls overlap, let's process it + this._maxOverlap = body.deltaAbsX() + this.OVERLAP_BIAS; - if (object.deltaX() != 0) + console.log('sx hulls over'); + console.log('x', body.hullX.x, 'y', body.hullX.y, 'bottom', body.hullX.y, 'right', body.hullX.right); + console.log(tile); + + if (body.deltaX() < 0) { - this._bounds1.setTo(object.x, object.y, object.width, object.height); + // Moving left + this._overlap = tile.right - body.hullX.x; - if ((this._bounds1.right > x) && (this._bounds1.x < x + width) && (this._bounds1.bottom > y) && (this._bounds1.y < y + height)) + console.log('sx left', this._overlap); + + if ((this._overlap > this._maxOverlap) || body.allowCollision.left == false || tile.tile.collideRight == false) { - // The hulls overlap, let's process it - this._maxOverlap = object.deltaAbsX() + this.OVERLAP_BIAS; + this._overlap = 0; + } + else + { + body.touching.left = true; + } + } + else + { + // Moving right + this._overlap = body.hullX.right - tile.x; - // 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 + console.log('sx right', this._overlap); - 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 > this._maxOverlap) || body.allowCollision.right == false || tile.tile.collideLeft == false) + { + this._overlap = 0; + } + else + { + body.touching.right = true; } } @@ -30822,21 +30847,37 @@ Phaser.Physics.Arcade.prototype = { { if (separate) { - object.x = object.x - this._overlap; - - if (object.bounce.x == 0) + if (body.deltaX() < 0) { - object.velocity.x = 0; + console.log('sx sep left 1', body.x); + body.x = body.x + this._overlap; + console.log('sx sep left 2', body.x); } else { - object.velocity.x = -object.velocity.x * object.bounce.x; + console.log('sx sep right 1', body.x); + body.x = body.x - this._overlap; + console.log('sx sep right 2', body.x); } + + if (body.bounce.x == 0) + { + body.velocity.x = 0; + } + else + { + body.velocity.x = -body.velocity.x * body.bounce.x; + } + + body.updateHulls(); } + + console.log('%c ', 'background: #7f7f7f') return true; } else { + console.log('%c ', 'background: #7f7f7f') return false; } @@ -30848,60 +30889,45 @@ Phaser.Physics.Arcade.prototype = { * @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) { + separateTileY: function (body, tile, separate) { // Can't separate two immovable objects (tiles are always immovable) - if (object.immovable) + if (body.immovable || body.deltaY() == 0 || Phaser.Rectangle.intersects(body.hullY, tile) == false) { return false; } - // First, get the object delta this._overlap = 0; - if (object.deltaY() != 0) + // The hulls overlap, let's process it + this._maxOverlap = body.deltaAbsY() + this.OVERLAP_BIAS; + + if (body.deltaY() < 0) { - this._bounds1.setTo(object.x, object.y, object.width, object.height); + // Moving up + this._overlap = tile.bottom - body.hullY.y; - if ((this._bounds1.right > x) && (this._bounds1.x < x + width) && (this._bounds1.bottom > y) && (this._bounds1.y < y + height)) + if ((this._overlap > this._maxOverlap) || body.allowCollision.up == false || tile.tile.collideDown == false) { - // The hulls overlap, let's process it + this._overlap = 0; + } + else + { + body.touching.up = true; + } + } + else + { + // Moving down + this._overlap = body.hullY.bottom - tile.y; - // 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; - } - } + if ((this._overlap > this._maxOverlap) || body.allowCollision.down == false || tile.tile.collideUp == false) + { + this._overlap = 0; + } + else + { + body.touching.down = true; } } @@ -30910,17 +30936,27 @@ Phaser.Physics.Arcade.prototype = { { if (separate) { - object.y = object.y - this._overlap; - - if (object.bounce.y == 0) + if (body.deltaY() < 0) { - object.velocity.y = 0; + body.y = body.y + this._overlap; } else { - object.velocity.y = -object.velocity.y * object.bounce.y; + body.y = body.y - this._overlap; } + + if (body.bounce.y == 0) + { + body.velocity.y = 0; + } + else + { + body.velocity.y = -body.velocity.y * body.bounce.y; + } + + body.updateHulls(); } + return true; } else @@ -30928,167 +30964,6 @@ 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. - */ - separateTileX: 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; - - // 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 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) - { - 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) - { - // console.log('x over', this._overlap); - 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. - */ - separateTileY: 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) - { - // console.log('y over', this._overlap); - - 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; - }, /** @@ -32641,10 +32516,36 @@ Phaser.Tile = function (tileset, index, x, y, width, height) { */ this.separateY = true; + /** + * @property {boolean} collisionCallback - Tilemap collision callback. + * @default + */ + this.collisionCallback = null; + + /** + * @property {boolean} collisionCallback - Tilemap collision callback. + * @default + */ + this.collisionCallbackContext = this; + }; Phaser.Tile.prototype = { + /** + * Set callback to be called when this tilemap collides. + * + * @method Phaser.Tilemap.prototype.setCollisionCallback + * @param {Function} callback - Callback function. + * @param {object} context - Callback will be called with this context. + */ + setCollisionCallback: function (callback, context) { + + this.collisionCallbackContext = context; + this.collisionCallback = callback; + + }, + /** * Clean up memory. * @method destroy @@ -32750,6 +32651,8 @@ Phaser.Tilemap = function (game, key) { this.layers = []; } + console.log(this.layers); + this.currentLayer = 0; this.debugMap = []; @@ -32808,6 +32711,23 @@ Phaser.Tilemap.prototype = { }, + /** + * Get the tile located at specific position (in world coordinate) and layer (thus you give a position of a point which is within the tile). + * @param {number} x - X position of the point in target tile. + * @param {number} y - Y position of the point in target tile. + * @param {number} [layer] - layer of this tile located. + * @return {Tile} The tile with specific properties. + */ + getTileFromWorldXY: function (x, y, layer) { + + if (typeof layer === "undefined") { layer = this.currentLayer; } + + + + // return this.tiles[this.layers[layer].getTileFromWorldXY(x, y)]; + + }, + /** * Set a specific tile with its x and y in tiles. * @method putTile @@ -32824,6 +32744,38 @@ Phaser.Tilemap.prototype = { }, + /** + * Set a specific tile with its x and y in tiles. + * @method putTileWorldXY + * @param {number} x - X position of this tile in world coordinates. + * @param {number} y - Y position of this tile in world coordinates. + * @param {number} index - The index of this tile type in the core map data. + */ + putTileWorldXY: function (x, y, index) { + + x = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth; + y = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight; + + if (x >= 0 && x < this.layers[this.currentLayer].width && y >= 0 && y < this.layers[this.currentLayer].height) + { + this.layers[this.currentLayer].data[y][x] = index; + } + + }, + + + // swapTile + // fillTile + // randomiseTiles + // replaceTiles + + removeAllLayers: function () { + + this.layers.length = 0; + this.currentLayer = 0; + + }, + dump: function () { var txt = ''; @@ -32858,6 +32810,13 @@ Phaser.Tilemap.prototype = { args[0] = txt; console.log.apply(console, args); + }, + + destroy: function () { + + this.removeAllLayers(); + this.game = null; + } }; @@ -32970,6 +32929,11 @@ Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset, * @private */ this._ty = 0; + + this._results = []; + + this._tw = 0; + this._th = 0; /** * @property {number} _tl - Local render loop var to help avoid gc spikes. @@ -33008,9 +32972,11 @@ Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset, this._y = 0; this._prevX = 0; this._prevY = 0; + + this.dirty = true; - if (typeof tileset === 'string') + if (tileset instanceof Phaser.Tileset || typeof tileset === 'string') { this.updateTileset(tileset); } @@ -33026,19 +32992,120 @@ Phaser.TilemapLayer.prototype = { updateTileset: function (tileset) { - this.tileset = this.game.cache.getTileset(tileset); + if (tileset instanceof Phaser.Tileset) + { + this.tileset = tileset; + } + else if (typeof tileset === 'string') + { + this.tileset = this.game.cache.getTileset('tiles'); + } + else + { + return; + } + this.tileWidth = this.tileset.tileWidth; this.tileHeight = this.tileset.tileHeight; - this.updateMax(); + }, - updateMapData: function (tilemap, layerID) { + updateMapData: function (tilemap, layer) { - this.tilemap = tilemap; - this.layer = this.tilemap.layers[layerID]; + if (typeof layer === 'undefined') + { + layer = 0; + } - this.updateMax(); + if (tilemap instanceof Phaser.Tilemap) + { + this.tilemap = tilemap; + this.layer = this.tilemap.layers[layer]; + this.updateMax(); + } + + }, + + /** + * + * @method getTileOverlaps + * @param {GameObject} object - Tiles you want to get that overlaps this. + * @return {array} Array with tiles informations (each contains x, y, and the tile). + */ + getTiles: 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; } + + // Cap the values + + if (x < 0) + { + x = 0; + } + + if (y < 0) + { + y = 0; + } + + if (width > this.widthInPixels) + { + width = this.widthInPixels; + } + + if (height > this.heightInPixels) + { + height = this.heightInPixels; + } + + var tileWidth = this.tileWidth * this.sprite.scale.x; + var tileHeight = this.tileHeight * this.sprite.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; + + this._results.length = 0; + + this._results.push( { x: x, y: y, width: width, height: height, tx: this._tx, ty: this._ty, tw: this._tw, th: this._th }); + + var _index = 0; + var _tile = null; + var sx = 0; + var sy = 0; + + 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]) + { + // Could combine + _index = this.layer.data[wy][wx] - 1; + _tile = this.tileset.getTile(_index); + + sx = _tile.width * this.sprite.scale.x; + sy = _tile.height * this.sprite.scale.y; + + if (collides == false || (collides && _tile.collideNone == false)) + { + // this._results.push({ x: wx * _tile.width, right: (wx * _tile.width) + _tile.width, y: wy * _tile.height, bottom: (wy * _tile.height) + _tile.height, width: _tile.width, height: _tile.height, tx: wx, ty: wy, tile: _tile }); + this._results.push({ x: wx * sx, right: (wx * sx) + sx, y: wy * sy, bottom: (wy * sy) + sy, width: sx, height: sy, tx: wx, ty: wy, tile: _tile }); + } + } + } + } + + return this._results; }, @@ -33444,11 +33511,43 @@ Phaser.Tileset.prototype = { }, + canCollide: function (index) { + + if (this.tiles[index]) + { + return this.tiles[index].collideNone; + } + + return null; + + }, + checkTileIndex: function (index) { return (this.tiles[index]); - } + }, + + setCollisionRange: function (start, stop, left, right, up, down) { + + if (this.tiles[start] && this.tiles[stop] && start < stop) + { + for (var i = start; i <= stop; i++) + { + this.tiles[i].setCollision(left, right, up, down); + } + } + + }, + + setCollision: function (index, left, right, up, down) { + + if (this.tiles[index]) + { + this.tiles[index].setCollision(left, right, up, down); + } + + }, } diff --git a/examples/animation/sprite sheet.php b/examples/animation/sprite sheet.php index e071ff984..3e4910884 100644 --- a/examples/animation/sprite sheet.php +++ b/examples/animation/sprite sheet.php @@ -28,7 +28,7 @@ // And this starts the animation playing by using its key ("walk") // 30 is the frame rate (30fps) // true means it will loop when it finishes - mummy.animations.play('walk', 30, true); + mummy.animations.play('walk', 20, true); } diff --git a/examples/assets/sprites/phaser-ship.png b/examples/assets/sprites/phaser-ship.png index a58eff302..86738ef79 100644 Binary files a/examples/assets/sprites/phaser-ship.png and b/examples/assets/sprites/phaser-ship.png differ diff --git a/examples/games/starstruck.php b/examples/games/starstruck.php index 8a1005ad2..5726ceece 100644 --- a/examples/games/starstruck.php +++ b/examples/games/starstruck.php @@ -11,7 +11,7 @@ function preload() { - game.load.tilemap('level1', 'assets/games/starstruck/tiles-1.png', 'assets/games/starstruck/level1.json', null, Phaser.Tilemap.JSON); + // game.load.tilemap('level1', 'assets/games/starstruck/tiles-1.png', 'assets/games/starstruck/level1.json', null, Phaser.Tilemap.JSON); game.load.spritesheet('dude', 'assets/games/starstruck/dude.png', 32, 48); game.load.spritesheet('droid', 'assets/games/starstruck/droid.png', 32, 32); game.load.image('starSmall', 'assets/games/starstruck/star.png'); diff --git a/examples/tilemaps/wip2.php b/examples/tilemaps/wip2.php index 74be00c23..09a510640 100644 --- a/examples/tilemaps/wip2.php +++ b/examples/tilemaps/wip2.php @@ -52,7 +52,7 @@ // This one gives tileset as a string, the other an object // layer = new Phaser.TilemapLayer(game, 0, 0, 640, 400, 'tiles', map, 0); - layer = new Phaser.TilemapLayer(game, 0, 0, 640, 400, tileset, map, 0); + layer = new Phaser.TilemapLayer(game, 0, 0, 800, 400, tileset, map, 0); // To set tiles for collision you need to modify the Tileset, which is a property of the layer diff --git a/examples/tilemaps/wip3.php b/examples/tilemaps/wip3.php new file mode 100644 index 000000000..7054db72f --- /dev/null +++ b/examples/tilemaps/wip3.php @@ -0,0 +1,201 @@ + + + + + \ No newline at end of file diff --git a/examples/tilemaps/wip4.php b/examples/tilemaps/wip4.php new file mode 100644 index 000000000..acf5807dc --- /dev/null +++ b/examples/tilemaps/wip4.php @@ -0,0 +1,210 @@ + + + + + \ No newline at end of file diff --git a/src/animation/AnimationManager.js b/src/animation/AnimationManager.js index a25f2806a..5b3b8b8aa 100644 --- a/src/animation/AnimationManager.js +++ b/src/animation/AnimationManager.js @@ -101,7 +101,7 @@ Phaser.AnimationManager.prototype = { // If they didn't set the useNumericIndex then let's at least try and guess it if (typeof useNumericIndex === 'undefined') { - if (frames && frames[0] && typeof frames[0] === 'number') + if (frames && typeof frames[0] === 'number') { useNumericIndex = true; } diff --git a/src/animation/FrameData.js b/src/animation/FrameData.js index d3275c846..59a7b5499 100644 --- a/src/animation/FrameData.js +++ b/src/animation/FrameData.js @@ -60,7 +60,7 @@ Phaser.FrameData.prototype = { */ getFrame: function (index) { - if (this._frames[index]) + if (this._frames.length > index) { return this._frames[index]; } diff --git a/src/geom/Rectangle.js b/src/geom/Rectangle.js index f6950e0f9..5b63e4211 100644 --- a/src/geom/Rectangle.js +++ b/src/geom/Rectangle.js @@ -661,6 +661,6 @@ Phaser.Rectangle.union = function (a, b, out) { if (typeof out === "undefined") { out = new Phaser.Rectangle(); } - return out.setTo(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.max(a.right, b.right), Math.max(a.bottom, b.bottom)); + return out.setTo(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.max(a.right, b.right) - Math.min(a.left, b.left), Math.max(a.bottom, b.bottom) - Math.min(a.top, b.top)); }; diff --git a/src/physics/arcade/Body.js b/src/physics/arcade/Body.js index 0a0da6142..c3567b89d 100644 --- a/src/physics/arcade/Body.js +++ b/src/physics/arcade/Body.js @@ -10,6 +10,8 @@ Phaser.Physics.Arcade.Body = function (sprite) { this.preX = sprite.x; this.preY = sprite.y; this.preRotation = sprite.angle; + this.screenX = sprite.x; + this.screenY = sprite.y; // un-scaled original size this.sourceWidth = sprite.currentFrame.sourceSizeW; @@ -108,8 +110,10 @@ Phaser.Physics.Arcade.Body.prototype = { 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.screenX = (this.sprite.worldTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x; + this.screenY = (this.sprite.worldTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y; + this.preX = (this.sprite.localTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x; + this.preY = (this.sprite.localTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y; this.preRotation = this.sprite.angle; this.x = this.preX; @@ -233,8 +237,10 @@ Phaser.Physics.Arcade.Body.prototype = { this.angularVelocity = 0; this.angularAcceleration = 0; - 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.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.preX = (this.sprite.localTransform[2] - (this.sprite.anchor.x * this.width)) + this.offset.x; + this.preY = (this.sprite.localTransform[5] - (this.sprite.anchor.y * this.height)) + this.offset.y; this.preRotation = this.sprite.angle; this.x = this.preX; diff --git a/src/system/Device.js b/src/system/Device.js index fffd771e6..5aa7cec3f 100644 --- a/src/system/Device.js +++ b/src/system/Device.js @@ -323,8 +323,7 @@ Phaser.Device.prototype = { this.file = !!window['File'] && !!window['FileReader'] && !!window['FileList'] && !!window['Blob']; this.fileSystem = !!window['requestFileSystem']; - this.webGL = ( function () { try { return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); } catch( e ) { return false; } } )(); - // this.webGL = !!window['WebGLRenderingContext']; + this.webGL = ( function () { try { var canvas = document.createElement( 'canvas' ); return !! window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ); } catch( e ) { return false; } } )(); this.worker = !!window['Worker']; if ('ontouchstart' in document.documentElement || window.navigator.msPointerEnabled) { diff --git a/src/tilemap/TilemapLayer.js b/src/tilemap/TilemapLayer.js index f05a8cb6c..908de2cea 100644 --- a/src/tilemap/TilemapLayer.js +++ b/src/tilemap/TilemapLayer.js @@ -37,6 +37,7 @@ Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset, * @default */ this.sprite = new Phaser.Sprite(this.game, x, y, this.texture, this.frame); + this.sprite.fixedToCamera = true; /** @@ -167,6 +168,21 @@ Phaser.TilemapLayer = function (game, x, y, renderWidth, renderHeight, tileset, Phaser.TilemapLayer.prototype = { + update: function () { + + this.x = this.game.camera.x; + this.y = this.game.camera.y; + + }, + + resizeWorld: function () { + + this.game.world.setBounds(0, 0, this.widthInPixels, this.heightInPixels); + + console.log('world', this.game.world.bounds); + + }, + updateTileset: function (tileset) { if (tileset instanceof Phaser.Tileset) @@ -242,11 +258,14 @@ Phaser.TilemapLayer.prototype = { height = this.heightInPixels; } + var tileWidth = this.tileWidth * this.sprite.scale.x; + var tileHeight = this.tileHeight * this.sprite.scale.y; + // Convert the pixel values into tile coordinates - this._tx = this.game.math.snapToFloor(x, this.tileWidth) / this.tileWidth; - this._ty = this.game.math.snapToFloor(y, this.tileHeight) / this.tileHeight; - this._tw = (this.game.math.snapToCeil(width, this.tileWidth) + this.tileWidth) / this.tileWidth; - this._th = (this.game.math.snapToCeil(height, this.tileHeight) + this.tileHeight) / this.tileHeight; + 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; this._results.length = 0; @@ -254,6 +273,8 @@ Phaser.TilemapLayer.prototype = { var _index = 0; var _tile = null; + var sx = 0; + var sy = 0; for (var wy = this._ty; wy < this._ty + this._th; wy++) { @@ -265,9 +286,13 @@ Phaser.TilemapLayer.prototype = { _index = this.layer.data[wy][wx] - 1; _tile = this.tileset.getTile(_index); + sx = _tile.width * this.sprite.scale.x; + sy = _tile.height * this.sprite.scale.y; + if (collides == false || (collides && _tile.collideNone == false)) { - this._results.push({ x: wx * _tile.width, right: (wx * _tile.width) + _tile.width, y: wy * _tile.height, bottom: (wy * _tile.height) + _tile.height, width: _tile.width, height: _tile.height, tx: wx, ty: wy, tile: _tile }); + // this._results.push({ x: wx * _tile.width, right: (wx * _tile.width) + _tile.width, y: wy * _tile.height, bottom: (wy * _tile.height) + _tile.height, width: _tile.width, height: _tile.height, tx: wx, ty: wy, tile: _tile }); + this._results.push({ x: wx * sx, right: (wx * sx) + sx, y: wy * sy, bottom: (wy * sy) + sy, width: sx, height: sy, tx: wx, ty: wy, tile: _tile }); } } } @@ -318,11 +343,6 @@ Phaser.TilemapLayer.prototype = { this._tx = this._dx; this._ty = this._dy; - // First let's just copy over the whole canvas, offset by the scroll difference - - // Then we only need fill in the missing strip/s (could be top/bottom/left/right I guess) - // ScrollZone code might be useful here. - this.context.clearRect(0, 0, this.canvas.width, this.canvas.height); for (var y = this._startY; y < this._startY + this._maxY; y++) diff --git a/src/utils/Debug.js b/src/utils/Debug.js index 6905d5ff3..0e9daa09c 100644 --- a/src/utils/Debug.js +++ b/src/utils/Debug.js @@ -626,8 +626,7 @@ Phaser.Utils.Debug.prototype = { this.start(0, 0, color); this.context.fillStyle = color; - // this.context.fillRect(sprite.body.x - sprite.body.deltaX(), sprite.body.y - sprite.body.deltaY(), sprite.body.width, sprite.body.height); - this.context.fillRect(sprite.body.x, sprite.body.y, sprite.body.width, sprite.body.height); + this.context.fillRect(sprite.body.screenX, sprite.body.screenY, sprite.body.width, sprite.body.height); this.stop();