Skip to content

Commit 1f513a3

Browse files
committed
Fixed an issue where passing null as the Group parent wouldn't set it to game.world as it should have (thanks tito100).
Continued work on the tilemap collision - again, please don't use this version if you need working tilemaps.
1 parent ea3802a commit 1f513a3

7 files changed

Lines changed: 119 additions & 90 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Bug Fixes:
6565
* Moved 'dirty' flag for Tilemap to a per-layer flag. Fixes #242
6666
* Group.length now returns the number of children in the Group regardless of their exists/alive state, or 0 if the Group is has no children.
6767
* Switch Camera.setBoundsToWorld to match world.bounds instead of world (thanks cocoademon)
68+
* Fixed an issue where passing null as the Group parent wouldn't set it to game.world as it should have (thanks tito100)
6869

6970

7071
You can view the Change Log for all previous versions at https://github.com/photonstorm/phaser/changelog.md

examples/wip/tilemap.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ function create() {
3636
// this screws something up - not quite sure what, but needs investigating!
3737
// layer.resizeWorld();
3838

39-
sprite = game.add.sprite(120, 510, 'phaser');
40-
sprite.anchor.setTo(0.5, 0.5);
39+
sprite = game.add.sprite(120, 450, 'phaser');
40+
// sprite.anchor.setTo(0.5, 0.5);
4141
// sprite.angle = 5;
4242

4343
// game.camera.follow(sprite);
@@ -96,12 +96,12 @@ function update() {
9696
if (cursors.left.isDown)
9797
{
9898
sprite.body.velocity.x = -150;
99-
sprite.scale.x = -1;
99+
// sprite.scale.x = -1;
100100
}
101101
else if (cursors.right.isDown)
102102
{
103103
sprite.body.velocity.x = 150;
104-
sprite.scale.x = 1;
104+
// sprite.scale.x = 1;
105105
}
106106

107107

@@ -113,6 +113,6 @@ function render() {
113113
// game.debug.renderSpriteBounds(sprite);
114114

115115
game.debug.renderText(sprite.x, 32, 32);
116-
game.debug.renderText(sprite.y, 32, 64);
116+
game.debug.renderText(sprite.y, 32, 48);
117117

118118
}

src/core/Group.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@
1010
* @classdesc A Group is a container for display objects that allows for fast pooling, recycling and collision checks.
1111
* @constructor
1212
* @param {Phaser.Game} game - A reference to the currently running game.
13-
* @param {*} parent - The parent Group or DisplayObjectContainer that will hold this group, if any.
13+
* @param {*} parent - The parent Group or DisplayObjectContainer that will hold this group, if any. If not set, or set to null, it will use game.world.
1414
* @param {string} [name=group] - A name for this Group. Not used internally but useful for debugging.
1515
* @param {boolean} [useStage=false] - Should the DisplayObjectContainer this Group creates be added to the World (default, false) or direct to the Stage (true).
1616
*/
1717
Phaser.Group = function (game, parent, name, useStage) {
1818

19-
if (typeof parent === 'undefined' || typeof parent === null)
20-
{
21-
parent = game.world;
22-
}
23-
24-
if (typeof useStage === 'undefined')
25-
{
26-
useStage = false;
27-
}
28-
2919
/**
3020
* @property {Phaser.Game} game - A reference to the currently running Game.
3121
*/
3222
this.game = game;
33-
23+
24+
if (typeof parent === 'undefined' || parent === null)
25+
{
26+
parent = game.world;
27+
}
28+
3429
/**
3530
* @property {string} name - A name for this Group. Not used internally but useful for debugging.
3631
*/
3732
this.name = name || 'group';
3833

34+
if (typeof useStage === 'undefined')
35+
{
36+
useStage = false;
37+
}
38+
3939
if (useStage)
4040
{
4141
this._container = this.game.stage._stage;

src/gameobjects/GameObjectFactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Phaser.GameObjectFactory.prototype = {
9090
*
9191
* @method Phaser.GameObjectFactory#group
9292
* @param {*} parent - The parent Group or DisplayObjectContainer that will hold this group, if any.
93-
* @param {string} [name=group] - A name for this Group. Not used internally but useful for debugging.
93+
* @param {string} [name='group'] - A name for this Group. Not used internally but useful for debugging.
9494
* @return {Phaser.Group} The newly created group.
9595
*/
9696
group: function (parent, name) {

src/geom/Rectangle.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,14 @@ Phaser.Rectangle.intersection = function (a, b, out) {
644644
*/
645645
Phaser.Rectangle.intersects = function (a, b) {
646646

647-
return (a.x < b.right && b.x < a.right && a.y < b.bottom && b.y < a.bottom);
647+
if (a.width <= 0 || a.height <= 0 || b.width <= 0 || b.height <= 0)
648+
{
649+
return false;
650+
}
651+
652+
return !(a.right < b.x || a.bottom < b.y || a.x > b.right || a.y > b.bottom);
653+
654+
// return (a.x < b.right && b.x < a.right && a.y < b.bottom && b.y < a.bottom);
648655

649656
// return (a.x <= b.right && b.x <= a.right && a.y <= b.bottom && b.y <= a.bottom);
650657

src/physics/arcade/ArcadePhysics.js

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,8 @@ Phaser.Physics.Arcade.prototype = {
566566
return;
567567
}
568568

569+
console.log('collideSpriteVsTilemapLayer', this._mapData.length);
570+
569571
for (var i = 0; i < this._mapData.length; i++)
570572
{
571573
if (this.separateTile(sprite.body, this._mapData[i]))
@@ -1006,31 +1008,41 @@ Phaser.Physics.Arcade.prototype = {
10061008
return false;
10071009
}
10081010

1009-
var overlapX = 0;
1010-
var overlapY = 0;
1011+
// use body var instead
1012+
body.overlapX = 0;
1013+
body.overlapY = 0;
10111014

1012-
console.log('x', tile.x, 'y', tile.y, 'r', tile.right, 'b', tile.bottom);
1013-
console.log('x', body.x, 'y', body.y, 'r', body.right, 'b', body.bottom);
1014-
console.log(Phaser.Rectangle.intersects(body, tile));
1015+
// Remember - this happens AFTER the body has been moved by the motion update, so it needs moving back again
1016+
// console.log('---------------------------------------------------------------------------------------------');
1017+
// console.log('tx', tile.x, 'ty', tile.y, 'tw', tile.width, 'th', tile.height, 'tr', tile.right, 'tb', tile.bottom);
1018+
// console.log('bx', body.x, 'by', body.y, 'bw', body.width, 'bh', body.height, 'br', body.right, 'bb', body.bottom);
1019+
// console.log(Phaser.Rectangle.intersects(body, tile));
1020+
// console.log('dx', body.deltaX(), 'dy', body.deltaY(), 'dax', body.deltaAbsX(), 'day', body.deltaAbsY(), 'cax', Math.ceil(body.deltaAbsX()), 'cay', Math.ceil(body.deltaAbsY()));
10151021

10161022
if (body.deltaX() < 0 && body.allowCollision.left && tile.tile.faceRight)
10171023
{
10181024
// LEFT
1019-
if (tile.right - body.x < Math.ceil(body.deltaAbsX()))
1020-
{
1021-
overlapX = tile.right - body.x;
1025+
body.overlapX = body.x - tile.right;
10221026

1027+
if (body.overlapX > body.deltaX())
1028+
{
1029+
console.log('left overlapX', body.overlapX);
1030+
// use touching instead of blocked?
1031+
body.blocked.left = true;
10231032
body.touching.left = true;
10241033
body.touching.none = false;
10251034
}
10261035
}
10271036
else if (body.deltaX() > 0 && body.allowCollision.right && tile.tile.faceLeft)
10281037
{
10291038
// RIGHT
1030-
if (body.right - tile.x < Math.ceil(body.deltaAbsX()))
1031-
{
1032-
overlapX = tile.x - body.right;
1039+
body.overlapX = body.right - tile.x;
10331040

1041+
// Distance check
1042+
if (body.overlapX < body.deltaX())
1043+
{
1044+
console.log('right overlapX', body.overlapX);
1045+
body.blocked.right = true;
10341046
body.touching.right = true;
10351047
body.touching.none = false;
10361048
}
@@ -1039,62 +1051,65 @@ Phaser.Physics.Arcade.prototype = {
10391051
if (body.deltaY() < 0 && body.allowCollision.up && tile.tile.faceBottom)
10401052
{
10411053
// UP
1042-
if (tile.bottom - body.y < Math.ceil(body.deltaAbsY()))
1043-
{
1044-
overlapY = tile.bottom - body.y;
1054+
body.overlapY = body.y - tile.bottom;
10451055

1056+
// Distance check
1057+
if (body.overlapY > body.deltaY())
1058+
{
1059+
console.log('up overlapY', body.overlapY);
1060+
body.blocked.up = true;
10461061
body.touching.up = true;
10471062
body.touching.none = false;
10481063
}
10491064
}
10501065
else if (body.deltaY() > 0 && body.allowCollision.down && tile.tile.faceTop)
10511066
{
10521067
// DOWN
1053-
if (body.bottom - tile.y < Math.ceil(body.deltaAbsY()))
1054-
{
1055-
overlapY = tile.y - body.bottom;
1068+
body.overlapY = body.bottom - tile.y;
10561069

1070+
if (body.overlapY < body.deltaY())
1071+
{
1072+
console.log('down overlapY', body.overlapY);
1073+
body.blocked.down = true;
10571074
body.touching.down = true;
10581075
body.touching.none = false;
10591076
}
10601077
}
10611078

10621079
// Separate in a single sweep
10631080

1064-
if (overlapX === 0 && overlapY === 0)
1081+
if (body.touching.none)
10651082
{
10661083
return false;
10671084
}
10681085

1069-
if (overlapX !== 0)
1086+
if (body.overlapX !== 0)
10701087
{
1071-
// body.overlapX = overlapX;
1072-
body.x += overlapX;
1073-
body.preX = body.x;
1088+
body.x -= body.overlapX;
1089+
body.preX -= body.overlapX;
10741090

10751091
if (body.bounce.x === 0)
10761092
{
1077-
body.velocity.x = 0;
1093+
// body.velocity.x = 0;
10781094
}
10791095
else
10801096
{
1081-
body.velocity.x = -body.velocity.x * body.bounce.x;
1097+
// body.velocity.x = -body.velocity.x * body.bounce.x;
10821098
}
10831099
}
10841100

1085-
if (overlapY !== 0)
1101+
if (body.overlapY !== 0)
10861102
{
1087-
// body.overlapY = overlapY;
1088-
body.y += overlapY;
1089-
body.preY = body.y;
1103+
body.y -= body.overlapY;
1104+
body.preY -= body.overlapY;
10901105

10911106
if (body.bounce.y === 0)
10921107
{
1093-
body.velocity.y = 0;
1108+
// body.velocity.y = 0;
10941109
}
10951110
else
10961111
{
1097-
body.velocity.y = -body.velocity.y * body.bounce.y;
1112+
// body.velocity.y = -body.velocity.y * body.bounce.y;
10981113
}
10991114
}
11001115

0 commit comments

Comments
 (0)