I’m new to Phaser and was looking at the breakout example and I came across a curiosity.
When a Collider is added we are passing in the bricks StaticPhysicsGroup, and the callback seems to use an ArcadeSprite object reference from within the StaticPhysicsGroup, children entries array . The callback then uses the StaticPhysicsGroup referenced from the Scene later in a conditional within that callback.
// add the bricks static physics group - line 27
this.bricks = this.physics.add.staticGroup({
key: 'assets', frame: [ 'blue1', 'red1', 'green1', 'yellow1', 'silver1', 'purple1' ],
frameQuantity: 10,
gridAlign: { width: 10, height: 6, cellWidth: 64, cellHeight: 32, x: 112, y: 100 }
});
// add the collider and pass in the StaticPhysicsGroup passing in the hitBrick callback- line 39
this.physics.add.collider(this.ball, this.bricks, this.hitBrick, null, this);
// hit brick call back on line 66 - see the brick reference (this should be the StaticPhysicsGroup
// but is an ArcadeSprite from the StaticPhysicsGroup children entries array - why?
hitBrick: function (ball, brick)
{
// Using the ArcadeSprite reference
brick.disableBody(true, true);
// using the StaticPhysicsGroup from the Scene reference (why does this not come through as a param in the callback?
if (this.bricks.countActive() === 0)
{
this.resetLevel();
}
},
This seem Odd. Why is the StaticPhysicsGroup passed to the collider but yet the ArcadeSprite is the reference that is used in the param list? How do we pass in the StaticPhysicsGroup and use the StaticPhysicsGroup as a reference so we don’t have to get it from the scene?
can we get a reference to both in the param list. e.g. ?
callback(ArcadeSprite1, ArcadeSprite2, StaticPhysicsGroup){...}
Thanks in advance.