* Added P2.Body.thrustLeft which will move the Body to the left by the speed given (thanks James Pryor)

* Added P2.Body.thrustRight which will move the Body to the right by the speed given (thanks James Pryor)
This commit is contained in:
Richard Davey 2016-03-01 22:31:58 +00:00
parent 763557af5d
commit 0c48c2d6a8
3 changed files with 40 additions and 1 deletions

View file

@ -320,6 +320,9 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
### New Features
* Added P2.Body.thrustLeft which will move the Body to the left by the speed given (thanks James Pryor)
* Added P2.Body.thrustRight which will move the Body to the right by the speed given (thanks James Pryor)
### Updates
* TypeScript definitions fixes and updates (thanks @clark-stevenson)

View file

@ -722,6 +722,40 @@ Phaser.Physics.P2.Body.prototype = {
},
/**
* Applies a force to the Body that causes it to 'thrust' to the left, based on its current angle and the given speed.
* The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).
*
* @method Phaser.Physics.P2.Body#thrustLeft
* @param {number} speed - The speed at which it should move to the left.
*/
thrustLeft: function (speed) {
var magnitude = this.world.pxmi(-speed);
var angle = this.data.angle;
this.data.force[0] += magnitude * Math.cos(angle);
this.data.force[1] += magnitude * Math.sin(angle);
},
/**
* Applies a force to the Body that causes it to 'thrust' to the right, based on its current angle and the given speed.
* The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).
*
* @method Phaser.Physics.P2.Body#thrustRight
* @param {number} speed - The speed at which it should move to the right.
*/
thrustRight: function (speed) {
var magnitude = this.world.pxmi(-speed);
var angle = this.data.angle;
this.data.force[0] -= magnitude * Math.cos(angle);
this.data.force[1] -= magnitude * Math.sin(angle);
},
/**
* Applies a force to the Body that causes it to 'thrust' backwards (in reverse), based on its current angle and the given speed.
* The speed is represented in pixels per second. So a value of 100 would move 100 pixels in 1 second (1000ms).

View file

@ -1,7 +1,7 @@
/// <reference path="pixi.d.ts" />
/// <reference path="p2.d.ts" />
// Type definitions for Phaser 2.4.6 - 18th February 2015
// Type definitions for Phaser 2.4.7 - 1st March 2016
// Project: https://github.com/photonstorm/phaser
declare module "phaser" {
@ -3351,6 +3351,8 @@ declare module Phaser {
setZeroVelocity(): void;
toLocalFrame(out: number[], worldPoint: number[]): void;
thrust(speed: number): void;
thrustLeft(speed: number): void;
thrustRight(speed: number): void;
toWorldFrame(out: number[], localPoint: number[]): void;
updateCollisionMask(shape?: p2.Shape): void;