mirror of
https://github.com/wassname/phaser.git
synced 2026-08-13 12:30:11 +08:00
Collision commands in and working. Updated sci-fly example. Multiple layers rendering. Mixed tile size on one layer rendering, but collision is grid bound.
This commit is contained in:
+81
-5
@@ -183,6 +183,20 @@ Phaser.Tilemap.prototype = {
|
||||
|
||||
},
|
||||
|
||||
// Region? Remove tile from map data?
|
||||
createSpritesFromTiles: function (layer, tileIndex, key, frame, group) {
|
||||
|
||||
if (typeof group === 'undefined') { group = this.game.world; }
|
||||
|
||||
},
|
||||
|
||||
createGroup: function (layer, parent) {
|
||||
|
||||
// Creates a Group based on an objectgroup, with one Sprite per gid entry, using the tilemap image + frame number
|
||||
// Will only work if image is loaded as spritesheet
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates a new TilemapLayer object. By default TilemapLayers are fixed to the camera.
|
||||
*
|
||||
@@ -195,6 +209,8 @@ Phaser.Tilemap.prototype = {
|
||||
*/
|
||||
createLayer: function (layer, width, height, group) {
|
||||
|
||||
// Add Buffer support for the left of the canvas
|
||||
|
||||
if (typeof width === 'undefined') { width = this.game.width; }
|
||||
if (typeof height === 'undefined') { height = this.game.height; }
|
||||
if (typeof group === 'undefined') { group = this.game.world; }
|
||||
@@ -290,15 +306,75 @@ Phaser.Tilemap.prototype = {
|
||||
|
||||
},
|
||||
|
||||
// TODO - set collision in an area, REMOVE collision
|
||||
|
||||
/**
|
||||
* Sets collision values on a range of tiles in the set.
|
||||
* Sets collision on all tiles in the given layer, except for the IDs of those in the given array.
|
||||
*
|
||||
* @method Phaser.Tileset#setCollisionByIndexRange
|
||||
* @param {number} start - The first index of the tile on the layer.
|
||||
* @param {number} stop - The last index of the tile on the layer.
|
||||
* @method Phaser.Tileset#setCollisionByExclusion
|
||||
* @param {array} indexes - An array of the tile IDs to not be counted for collision.
|
||||
* @param {number|string|Phaser.TilemapLayer} layer - The layer to operate on. If not given will default to this.currentLayer.
|
||||
*/
|
||||
setCollisionByIndexRange: function (start, stop, layer) {
|
||||
setCollisionByExclusion: function (indexes, layer) {
|
||||
|
||||
if (typeof layer === 'undefined')
|
||||
{
|
||||
layer = this.currentLayer;
|
||||
}
|
||||
|
||||
// Collide everything, except the IDs given in the indexes array
|
||||
for (var i = 0, len = this.tiles.length; i < len; i++)
|
||||
{
|
||||
if (indexes.indexOf(i) === -1)
|
||||
{
|
||||
this.setCollisionByIndex(i, layer, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Now re-calculate interesting faces
|
||||
this.calculateFaces(layer);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets collision the given tile index, or array of tiles indexes.
|
||||
*
|
||||
* @method Phaser.Tileset#setCollision
|
||||
* @param {number|array} indexes - Either a single tile index, or an array of tile IDs to be checked for collision.
|
||||
* @param {number|string|Phaser.TilemapLayer} layer - The layer to operate on. If not given will default to this.currentLayer.
|
||||
*/
|
||||
setCollision: function (indexes, layer) {
|
||||
|
||||
if (typeof layer === 'undefined')
|
||||
{
|
||||
layer = this.currentLayer;
|
||||
}
|
||||
|
||||
if (typeof indexes === 'number')
|
||||
{
|
||||
return this.setCollisionByIndex(indexes, layer);
|
||||
}
|
||||
|
||||
// Collide all of the IDs given in the indexes array
|
||||
for (var i = 0, len = indexes.length; i < len; i++)
|
||||
{
|
||||
this.setCollisionByIndex(i, layer, false);
|
||||
}
|
||||
|
||||
// Now re-calculate interesting faces
|
||||
this.calculateFaces(layer);
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets collision on a range of tiles.
|
||||
*
|
||||
* @method Phaser.Tileset#setCollisionBetween
|
||||
* @param {number} start - The first index of the tile to be set for collision.
|
||||
* @param {number} stop - The last index of the tile to be set for collision.
|
||||
* @param {number|string|Phaser.TilemapLayer} layer - The layer to operate on. If not given will default to this.currentLayer.
|
||||
*/
|
||||
setCollisionBetween: function (start, stop, layer) {
|
||||
|
||||
if (start > stop)
|
||||
{
|
||||
|
||||
+58
-62
@@ -477,10 +477,10 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides
|
||||
}
|
||||
|
||||
// Convert the pixel values into tile coordinates
|
||||
this._tx = this.game.math.snapToFloor(x, this.map.tileWidth) / this.map.tileWidth;
|
||||
this._ty = this.game.math.snapToFloor(y, this.map.tileHeight) / this.map.tileHeight;
|
||||
this._tw = (this.game.math.snapToCeil(width, this.map.tileWidth) + this.map.tileWidth) / this.map.tileWidth;
|
||||
this._th = (this.game.math.snapToCeil(height, this.map.tileHeight) + this.map.tileHeight) / this.map.tileHeight;
|
||||
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;
|
||||
|
||||
// This should apply the layer x/y here
|
||||
this._results.length = 0;
|
||||
@@ -500,14 +500,14 @@ Phaser.TilemapLayer.prototype.getTiles = function (x, y, width, height, collides
|
||||
if (collides === false || (collides && _tile.collides))
|
||||
{
|
||||
// convert tile coordinates back to camera space for return
|
||||
var _wx = this._unfixX(wx * this.map.tileWidth) / this.map.tileWidth;
|
||||
var _wy = this._unfixY(wy * this.map.tileHeight) / this.map.tileHeight;
|
||||
var _wx = this._unfixX(wx * this._cw) / this._cw;
|
||||
var _wy = this._unfixY(wy * this._ch) / this._ch;
|
||||
|
||||
this._results.push({
|
||||
x: _wx * this.map.tileWidth,
|
||||
y: _wy * this.map.tileHeight,
|
||||
right: (_wx * this.map.tileWidth) + this.map.tileWidth,
|
||||
bottom: (_wy * this.map.tileHeight) + this.map.tileHeight,
|
||||
x: _wx * this._cw,
|
||||
y: _wy * this._ch,
|
||||
right: (_wx * this._cw) + this._cw,
|
||||
bottom: (_wy * this._ch) + this._ch,
|
||||
tile: _tile
|
||||
});
|
||||
}
|
||||
@@ -687,7 +687,7 @@ 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);
|
||||
// console.log('updateMax', this._maxX, this._maxY, 'px', this.layer.widthInPixels, this.layer.heightInPixels, 'rwh', this.layer.width, this.layer.height);
|
||||
|
||||
}
|
||||
|
||||
@@ -824,8 +824,6 @@ Phaser.TilemapLayer.prototype.renderDebug = function () {
|
||||
this.context.strokeStyle = this.debugColor;
|
||||
this.context.fillStyle = this.debugFillColor;
|
||||
|
||||
var set;
|
||||
|
||||
for (var y = this._startY, lenY = this._startY + this._maxY; y < lenY; y++)
|
||||
{
|
||||
this._column = this.layer.data[y];
|
||||
@@ -836,13 +834,11 @@ Phaser.TilemapLayer.prototype.renderDebug = function () {
|
||||
|
||||
if (tile && (tile.faceTop || tile.faceBottom || tile.faceLeft || tile.faceRight))
|
||||
{
|
||||
set = this.map.tilesets[this.map.tiles[tile.index][2]]
|
||||
|
||||
this._tx = Math.floor(this._tx);
|
||||
|
||||
if (this.debugFill)
|
||||
{
|
||||
this.context.fillRect(this._tx, this._ty, set.tileWidth, set.tileHeight);
|
||||
this.context.fillRect(this._tx, this._ty, this._cw, this._ch);
|
||||
}
|
||||
|
||||
this.context.beginPath();
|
||||
@@ -850,25 +846,25 @@ Phaser.TilemapLayer.prototype.renderDebug = function () {
|
||||
if (tile.faceTop)
|
||||
{
|
||||
this.context.moveTo(this._tx, this._ty);
|
||||
this.context.lineTo(this._tx + set.tileWidth, this._ty);
|
||||
this.context.lineTo(this._tx + this._cw, this._ty);
|
||||
}
|
||||
|
||||
if (tile.faceBottom)
|
||||
{
|
||||
this.context.moveTo(this._tx, this._ty + set.tileHeight);
|
||||
this.context.lineTo(this._tx + set.tileWidth, this._ty + set.tileHeight);
|
||||
this.context.moveTo(this._tx, this._ty + this._ch);
|
||||
this.context.lineTo(this._tx + this._cw, this._ty + this._ch);
|
||||
}
|
||||
|
||||
if (tile.faceLeft)
|
||||
{
|
||||
this.context.moveTo(this._tx, this._ty);
|
||||
this.context.lineTo(this._tx, this._ty + set.tileHeight);
|
||||
this.context.lineTo(this._tx, this._ty + this._ch);
|
||||
}
|
||||
|
||||
if (tile.faceRight)
|
||||
{
|
||||
this.context.moveTo(this._tx + set.tileWidth, this._ty);
|
||||
this.context.lineTo(this._tx + set.tileWidth, this._ty + set.tileHeight);
|
||||
this.context.moveTo(this._tx + this._cw, this._ty);
|
||||
this.context.lineTo(this._tx + this._cw, this._ty + this._ch);
|
||||
}
|
||||
|
||||
this.context.stroke();
|
||||
@@ -885,46 +881,6 @@ Phaser.TilemapLayer.prototype.renderDebug = function () {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the absolute delta x value.
|
||||
* @method Phaser.TilemapLayer#deltaAbsX
|
||||
* @memberof Phaser.TilemapLayer
|
||||
* @return {number} Absolute delta X value
|
||||
*/
|
||||
// Phaser.TilemapLayer.prototype.deltaAbsX = function () {
|
||||
// return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX());
|
||||
// }
|
||||
|
||||
/**
|
||||
* Returns the absolute delta y value.
|
||||
* @method Phaser.TilemapLayer#deltaAbsY
|
||||
* @memberof Phaser.TilemapLayer
|
||||
* @return {number} Absolute delta Y value
|
||||
*/
|
||||
// Phaser.TilemapLayer.prototype.deltaAbsY = function () {
|
||||
// return (this.deltaY() > 0 ? this.deltaY() : -this.deltaY());
|
||||
// }
|
||||
|
||||
/**
|
||||
* Returns the delta x value.
|
||||
* @method Phaser.TilemapLayer#deltaX
|
||||
* @memberof Phaser.TilemapLayer
|
||||
* @return {number} Delta X value
|
||||
*/
|
||||
// Phaser.TilemapLayer.prototype.deltaX = function () {
|
||||
// return this._dx - this._prevX;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Returns the delta y value.
|
||||
* @method Phaser.TilemapLayer#deltaY
|
||||
* @memberof Phaser.TilemapLayer
|
||||
* @return {number} Delta Y value
|
||||
*/
|
||||
// Phaser.TilemapLayer.prototype.deltaY = function () {
|
||||
// return this._dy - this._prevY;
|
||||
// }
|
||||
|
||||
/**
|
||||
* @name Phaser.TilemapLayer#scrollX
|
||||
* @property {number} scrollX - Scrolls the map horizontally or returns the current x position.
|
||||
@@ -1006,3 +962,43 @@ Object.defineProperty(Phaser.TilemapLayer.prototype, "scrollY", {
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.TilemapLayer#collisionWidth
|
||||
* @property {number} collisionWidth - The width of the collision tiles.
|
||||
*/
|
||||
Object.defineProperty(Phaser.TilemapLayer.prototype, "collisionWidth", {
|
||||
|
||||
get: function () {
|
||||
return this._cw;
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this._cw = value;
|
||||
|
||||
this.dirty = true;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.TilemapLayer#collisionHeight
|
||||
* @property {number} collisionHeight - The height of the collision tiles.
|
||||
*/
|
||||
Object.defineProperty(Phaser.TilemapLayer.prototype, "collisionHeight", {
|
||||
|
||||
get: function () {
|
||||
return this._ch;
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
|
||||
this._ch = value;
|
||||
|
||||
this.dirty = true;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user