mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 20:53:39 +00:00
* 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:
parent
763557af5d
commit
0c48c2d6a8
3 changed files with 40 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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).
|
||||
|
|
4
typescript/phaser.d.ts
vendored
4
typescript/phaser.d.ts
vendored
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue