mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 20:53:39 +00:00
Arcade Physics Body has a new property worldBounce
. This controls the elasticity of the Body specifically when colliding with the World bounds. By default this property is null
, in which case Body.bounce is used instead. Set this property to a Phaser.Point object in order to enable a World bounds specific bounce value (thanks @VitaZheltyakov #2465)
This commit is contained in:
parent
f9994fac75
commit
ac89d1aec7
3 changed files with 17 additions and 4 deletions
|
@ -341,6 +341,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
|
|||
|
||||
* BitmapData.copy, and by extension any method that uses it, including BitmapData.draw, drawGroup and drawFull, now all support drawing RenderTexture objects. These can either be passed directly, or be the textures of Sprites, such as from a call to generateTexture.
|
||||
* Arcade Physics has had a new `world` argument added to the following functions: `distanceBetween`, `distanceToXY`, `distanceToPointer`, `angleBetween`, `angleToXY` and `angleToPointer`. The argument (which is false by default), when enabled will calculate the angles or distances based on the Game Objects `world` property, instead of its `x` and `y` properties. This allows it to work for objects that are placed in offset Groups, or are children of other display objects (thanks @Skeptron for the thread #2463)
|
||||
* Arcade Physics Body has a new property `worldBounce`. This controls the elasticity of the Body specifically when colliding with the World bounds. By default this property is `null`, in which case Body.bounce is used instead. Set this property to a Phaser.Point object in order to enable a World bounds specific bounce value (thanks @VitaZheltyakov #2465)
|
||||
|
||||
### Updates
|
||||
|
||||
|
|
|
@ -161,6 +161,14 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
|||
*/
|
||||
this.bounce = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* The elasticity of the Body when colliding with the World bounds.
|
||||
* By default this property is `null`, in which case `Body.bounce` is used instead. Set this property
|
||||
* to a Phaser.Point object in order to enable a World bounds specific bounce value.
|
||||
* @property {Phaser.Point} worldBounce
|
||||
*/
|
||||
this.worldBounce = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} maxVelocity - The maximum velocity in pixels per second sq. that the Body can reach.
|
||||
* @default
|
||||
|
@ -581,29 +589,32 @@ Phaser.Physics.Arcade.Body.prototype = {
|
|||
var bounds = this.game.physics.arcade.bounds;
|
||||
var check = this.game.physics.arcade.checkCollision;
|
||||
|
||||
var bx = (this.worldBounce) ? -this.worldBounce.x : -this.bounce.x;
|
||||
var by = (this.worldBounce) ? -this.worldBounce.y : -this.bounce.y;
|
||||
|
||||
if (pos.x < bounds.x && check.left)
|
||||
{
|
||||
pos.x = bounds.x;
|
||||
this.velocity.x *= -this.bounce.x;
|
||||
this.velocity.x *= bx;
|
||||
this.blocked.left = true;
|
||||
}
|
||||
else if (this.right > bounds.right && check.right)
|
||||
{
|
||||
pos.x = bounds.right - this.width;
|
||||
this.velocity.x *= -this.bounce.x;
|
||||
this.velocity.x *= bx;
|
||||
this.blocked.right = true;
|
||||
}
|
||||
|
||||
if (pos.y < bounds.y && check.up)
|
||||
{
|
||||
pos.y = bounds.y;
|
||||
this.velocity.y *= -this.bounce.y;
|
||||
this.velocity.y *= by;
|
||||
this.blocked.up = true;
|
||||
}
|
||||
else if (this.bottom > bounds.bottom && check.down)
|
||||
{
|
||||
pos.y = bounds.bottom - this.height;
|
||||
this.velocity.y *= -this.bounce.y;
|
||||
this.velocity.y *= by;
|
||||
this.blocked.down = true;
|
||||
}
|
||||
|
||||
|
|
1
typescript/phaser.d.ts
vendored
1
typescript/phaser.d.ts
vendored
|
@ -2937,6 +2937,7 @@ declare module Phaser {
|
|||
type: number;
|
||||
wasTouching: FaceChoices;
|
||||
width: number;
|
||||
worldBounce: Phaser.Point;
|
||||
velocity: Phaser.Point;
|
||||
x: number;
|
||||
y: number;
|
||||
|
|
Loading…
Reference in a new issue