mirror of
https://github.com/wassname/phaser.git
synced 2026-07-17 11:31:30 +08:00
Fixed some issues in Tilemap collision, updated the Emitter so x/y controls the point of emission (to stop collision getting out of whack) and fixed the postUpdate in body.
This commit is contained in:
@@ -17,12 +17,12 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
|
||||
/**
|
||||
* The X position of the top left corner of the emitter in world space.
|
||||
*/
|
||||
this.x = x;
|
||||
this.x = 0;
|
||||
|
||||
/**
|
||||
* The Y position of the top left corner of emitter in world space.
|
||||
*/
|
||||
this.y = y;
|
||||
this.y = 0;
|
||||
|
||||
/**
|
||||
* The width of the emitter. Particles can be randomly generated from anywhere within this box.
|
||||
@@ -141,8 +141,8 @@ Phaser.Particles.Arcade.Emitter = function (game, x, y, maxParticles) {
|
||||
* Emitter.x and Emitter.y control the containers location, which updates all current particles
|
||||
* Emitter.emitX and Emitter.emitY control the emission location relative to the x/y position.
|
||||
*/
|
||||
this.emitX = 0;
|
||||
this.emitY = 0;
|
||||
this.emitX = x;
|
||||
this.emitY = y;
|
||||
|
||||
};
|
||||
|
||||
@@ -241,6 +241,7 @@ Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (keys, frames
|
||||
if (collide > 0)
|
||||
{
|
||||
particle.body.allowCollision.any = true;
|
||||
particle.body.allowCollision.none = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -495,6 +496,30 @@ Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "visible", {
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "x", {
|
||||
|
||||
get: function () {
|
||||
return this.emitX;
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
this.emitX = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "y", {
|
||||
|
||||
get: function () {
|
||||
return this.emitY;
|
||||
},
|
||||
|
||||
set: function (value) {
|
||||
this.emitY = value;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Object.defineProperty(Phaser.Particles.Arcade.Emitter.prototype, "left", {
|
||||
|
||||
get: function () {
|
||||
|
||||
@@ -124,8 +124,8 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
|
||||
postUpdate: function () {
|
||||
|
||||
this.sprite.x = this.x;
|
||||
this.sprite.y = this.y;
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -336,7 +336,6 @@ Phaser.Tilemap.prototype.collide = function (objectOrGroup, callback, context) {
|
||||
this.collisionCallbackContext = context;
|
||||
}
|
||||
|
||||
// Group?
|
||||
if (objectOrGroup instanceof Phaser.Group)
|
||||
{
|
||||
objectOrGroup.forEachAlive(this.collideGameObject, this);
|
||||
@@ -364,7 +363,7 @@ Phaser.Tilemap.prototype.collideGameObject = function (object) {
|
||||
{
|
||||
this._tempCollisionData = this.collisionLayer.getTileOverlaps(object);
|
||||
|
||||
if (this.collisionCallback !== null && this._tempCollisionData.length > 0)
|
||||
if (this.collisionCallback && this._tempCollisionData.length > 0)
|
||||
{
|
||||
this.collisionCallback.call(this.collisionCallbackContext, object, this._tempCollisionData);
|
||||
}
|
||||
|
||||
@@ -94,6 +94,7 @@ Phaser.TilemapLayer = function (parent, id, key, mapFormat, name, tileWidth, til
|
||||
|
||||
this.mapData = [];
|
||||
this._tempTileBlock = [];
|
||||
this._tempBlockResults = [];
|
||||
|
||||
};
|
||||
|
||||
@@ -305,10 +306,12 @@ Phaser.TilemapLayer.prototype = {
|
||||
*/
|
||||
getTileOverlaps: function (object) {
|
||||
|
||||
this._tempBlockResults.length = 0;
|
||||
|
||||
// If the object is outside of the world coordinates then abort the check (tilemap has to exist within world bounds)
|
||||
if (object.body.x < 0 || object.body.x > this.widthInPixels || object.body.y < 0 || object.body.bottom > this.heightInPixels)
|
||||
{
|
||||
return;
|
||||
return this._tempBlockResults;
|
||||
}
|
||||
|
||||
// What tiles do we need to check against?
|
||||
@@ -318,13 +321,10 @@ Phaser.TilemapLayer.prototype = {
|
||||
this._tempTileH = (this.game.math.snapToCeil(object.body.height, this.tileHeight) + this.tileHeight) / this.tileHeight;
|
||||
|
||||
// Loop through the tiles we've got and check overlaps accordingly (the results are stored in this._tempTileBlock)
|
||||
this._tempBlockResults = [];
|
||||
|
||||
this.getTempBlock(this._tempTileX, this._tempTileY, this._tempTileW, this._tempTileH, true);
|
||||
|
||||
for (var r = 0; r < this._tempTileBlock.length; r++)
|
||||
{
|
||||
// separateTile: function (object, x, y, width, height, mass, collideLeft, collideRight, collideUp, collideDown, separateX, separateY)
|
||||
if (this.game.physics.separateTile(object, this._tempTileBlock[r].x * this.tileWidth, this._tempTileBlock[r].y * this.tileHeight, this.tileWidth, this.tileHeight, this._tempTileBlock[r].tile.mass, this._tempTileBlock[r].tile.collideLeft, this._tempTileBlock[r].tile.collideRight, this._tempTileBlock[r].tile.collideUp, this._tempTileBlock[r].tile.collideDown, this._tempTileBlock[r].tile.separateX, this._tempTileBlock[r].tile.separateY))
|
||||
{
|
||||
this._tempBlockResults.push({ x: this._tempTileBlock[r].x, y: this._tempTileBlock[r].y, tile: this._tempTileBlock[r].tile });
|
||||
|
||||
Reference in New Issue
Block a user