mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 20:53:39 +00:00
Renamed alignTo to alignIn, and added the new method alignTo, to allow for Sprite to Sprite alignment. Updated all of the Bounds and TS defs.
This commit is contained in:
parent
5bcf84f5a4
commit
4da3b15ae2
7 changed files with 271 additions and 49 deletions
17
README.md
17
README.md
|
@ -38,9 +38,14 @@ Grab the source and join in the fun!
|
|||
|
||||
<div align="center"><img src="http://phaser.io/images/github/news.jpg"></div>
|
||||
|
||||
> In Development
|
||||
> 16th June 2016
|
||||
|
||||
Phaser 2.4.9 is the latest version of Phaser, and represents another significant milestone in the evolution of the framework in 2016.
|
||||
|
||||
As well as fixing a number of issues, there are some genuinely useful new features added in this release. Not least of which includes the new Weapons Plugin, making creating bullet pools a couple lines of code. Don't worry, it's also easy to exclude from custom builds too.
|
||||
|
||||
There are also some subtle but significant updates to Groups. The `createMultiple` method has had a nice overhaul, now able to take Arrays of image keys and frames. `Group.align` allows you to align the children of a Group in a grid formation, with the dimensions and spacing of the grid under your control. Continuing on that theme, all Game Objects (such as Sprites) now have a new method `alignIn`, which allows you to easily align them within another Game Object, or Rectangle. Making it now trivial to do things like placing sprites into the corners of the game world, or each other.
|
||||
|
||||
The release of Phaser 2.4.9 is currently in development. This README will be updated as development continues.
|
||||
|
||||
As always, keep you eyes on the Phaser web site and read our weekly [newsletter](#newsletter). You can also follow me on [Twitter](https://twitter.com/photonstorm) or chat to me in the Phaser [Slack](http://phaser.io/news/2015/08/phaser-slack-channel) channel.
|
||||
|
||||
|
@ -348,11 +353,13 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
|
|||
* BitmapData.smoothProperty is a new property that holds the string based prefix needed to set image scaling on the BitmapData context.
|
||||
* BitmapData.copyTransform allows you to draw a Game Object to the BitmapData, using its `worldTransform` property to control the location, scaling and rotation of the object. You can optionally provide
|
||||
* BitmapData.drawGroup now uses the new `copyTransform` method, to provide for far more accurate results. Previously nested Game Objects wouldn't render correctly, nor would Sprites added via `addChild` to another Sprite. BitmapText objects also rendered without rotation taken into account, and the Sprites smoothing property was ignored. All of these things are now covered by the new drawGroup method, which also handles full deep iteration down the display list.
|
||||
* Added the following new constants: `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.MIDDLE_LEFT`, `Phaser.MIDDLE_CENTER`, `Phaser.MIDDLE_RIGHT`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` and `Phaser.BOTTOM_RIGHT`.
|
||||
* Rectangle.getPoint is a new method that returns a point based on the given location constant, such as `Phaser.BOTTOM_LEFT`. It returns the same result as calling `Rectangle.bottomLeft` (etc) but unlike those getters you are able to provide your own Point object.
|
||||
* Added the following new constants: `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`, `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.CENTER`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`, `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` and `Phaser.BOTTOM_RIGHT`.
|
||||
* Rectangle.getPoint is a new method that returns a point based on the given position constant, such as `Phaser.BOTTOM_LEFT`. It returns the same result as calling `Rectangle.bottomLeft` (etc) but unlike those getters you are able to provide your own Point object.
|
||||
* The Game Object Bounds component has been updated to include two new properties: `centerX` and `centerY`. This means you can, for example, now get the horizontal center of a Sprite by called `Sprite.centerX`. These properties are also setters, so you can position the Game Objects, and it will take scale and anchor into consideration.
|
||||
* All Game Objects with the Bounds component; which includes Sprites, Images, Text, BitmapText, TileSprites and anything that extend these, now have a new method `alignTo`. It allows you to align the Game Object to another Game Object, or a Rectangle. You can specify one of 9 positions which are the new constants: `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER` and so on (see above for the complete list). The Game Objects are positioned based on their Bounds, which takes rotation, scaling and anchor into consideration. You can easily place Sprites into the corners or the screen or game world, or align them against other Sprites, using this method.
|
||||
* All Game Objects with the Bounds component; which includes Sprites, Images, Text, BitmapText, TileSprites and anything that extend these, now have the new method `alignIn`. It allows you to align the Game Object within another Game Object, or a Rectangle. You can specify one of 9 positions which are the new position constants such as: `Phaser.TOP_LEFT` or `Phaser.CENTER` (see above for the complete list). The Game Objects are positioned based on their Bounds, which takes rotation, scaling and anchor into consideration. You can easily place Sprites into the corners of the screen, or game world, or align them within other Sprites, using this method.
|
||||
* All Game Objects with the Bounds component; which includes Sprites, Images, Text, BitmapText, TileSprites and anything that extend these, now have the new method `alignTo`. It allows you to align a Game Object to the side of another Game Object, or a Rectangle. You can specify one of 11 positions which are the new position constants such as: `Phaser.TOP_LEFT` or `Phaser.LEFT_BOTTOM` (see above for the complete list). The Game Objects are positioned based on their Bounds, which takes rotation, scaling and anchor into consideration. You can easily align Sprites next to other Sprites using this method.
|
||||
* Group.align is a new method that allows you to layout all the children of the Group in a grid formation. You can specify the dimensions of the grid, including the width, height and cell size. You can also control where children are positioned within each grid cell. The grid width and height values can also be set to -1, making them fluid, so the grid expands until all children are aligned. Finally an optional child index argument can be set. This is a great way to quickly and comprehensively align Group children, and has lots of use cases.
|
||||
* The Arcade Physics Body has two new experimental methods: `moveTo` and `moveFrom`. These allow you to move a Physics Body for a given distance, or duration, after which it will stop and emit the `onMoveComplete` Signal. It is still capable of colliding and rebounding like usual.
|
||||
|
||||
### Updates
|
||||
|
||||
|
|
|
@ -386,63 +386,91 @@ var Phaser = Phaser || {
|
|||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
TOP_LEFT: 50,
|
||||
TOP_LEFT: 0,
|
||||
|
||||
/**
|
||||
* A constant representing a top-center alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
TOP_CENTER: 51,
|
||||
TOP_CENTER: 1,
|
||||
|
||||
/**
|
||||
* A constant representing a top-right alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
TOP_RIGHT: 52,
|
||||
TOP_RIGHT: 2,
|
||||
|
||||
/**
|
||||
* A constant representing a middle-left alignment or position.
|
||||
* A constant representing a left-top alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
MIDDLE_LEFT: 53,
|
||||
LEFT_TOP: 3,
|
||||
|
||||
/**
|
||||
* A constant representing a middle-center alignment or position.
|
||||
* A constant representing a left-center alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
MIDDLE_CENTER: 54,
|
||||
LEFT_CENTER: 4,
|
||||
|
||||
/**
|
||||
* A constant representing a middle-right alignment or position.
|
||||
* A constant representing a left-bottom alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
MIDDLE_RIGHT: 55,
|
||||
LEFT_BOTTOM: 5,
|
||||
|
||||
/**
|
||||
* A constant representing a center alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
CENTER: 6,
|
||||
|
||||
/**
|
||||
* A constant representing a right-top alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
RIGHT_TOP: 7,
|
||||
|
||||
/**
|
||||
* A constant representing a right-center alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
RIGHT_CENTER: 8,
|
||||
|
||||
/**
|
||||
* A constant representing a right-bottom alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
RIGHT_BOTTOM: 9,
|
||||
|
||||
/**
|
||||
* A constant representing a bottom-left alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
BOTTOM_LEFT: 56,
|
||||
BOTTOM_LEFT: 10,
|
||||
|
||||
/**
|
||||
* A constant representing a bottom-center alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
BOTTOM_CENTER: 57,
|
||||
BOTTOM_CENTER: 11,
|
||||
|
||||
/**
|
||||
* A constant representing a bottom-right alignment or position.
|
||||
* @constant
|
||||
* @type {integer}
|
||||
*/
|
||||
BOTTOM_RIGHT: 58,
|
||||
BOTTOM_RIGHT: 12,
|
||||
|
||||
/**
|
||||
* Various blend modes supported by Pixi.
|
||||
|
|
|
@ -709,7 +709,9 @@ Phaser.Group.prototype.updateZ = function () {
|
|||
* all of the children in.
|
||||
*
|
||||
* The `position` property allows you to control where in each grid cell the child is positioned.
|
||||
* This is a constant, such as `Phaser.TOP_RIGHT` or `Phaser.MIDDLE_CENTER`.
|
||||
* This is a constant and can be one of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`,
|
||||
* `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, `Phaser.CENTER`, `Phaser.RIGHT_CENTER`,
|
||||
* `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`.
|
||||
*
|
||||
* The final argument; `offset` lets you start the alignment from a specific child index.
|
||||
*
|
||||
|
@ -718,7 +720,7 @@ Phaser.Group.prototype.updateZ = function () {
|
|||
* @param {integer} columns - The number of columns, or height, of the grid. Set to -1 for a dynamic height.
|
||||
* @param {integer} cellWidth - The width of each grid cell, in pixels.
|
||||
* @param {integer} cellHeight - The height of each grid cell, in pixels.
|
||||
* @param {integer} [position] - The position constant. One of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.MIDDLE_LEFT`, `Phaser.MIDDLE_CENTER`, `Phaser.MIDDLE_RIGHT`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`.
|
||||
* @param {integer} [position] - The position constant. One of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`.
|
||||
* @param {integer} [offset=0] - Optional index to start the alignment from. Defaults to zero, the first child in the Group, but can be set to any valid child index value.
|
||||
*/
|
||||
Phaser.Group.prototype.align = function (rows, columns, cellWidth, cellHeight, position, offset) {
|
||||
|
@ -739,9 +741,9 @@ Phaser.Group.prototype.align = function (rows, columns, cellWidth, cellHeight, p
|
|||
{
|
||||
var child = this.children[i];
|
||||
|
||||
if (child['alignTo'])
|
||||
if (child['alignIn'])
|
||||
{
|
||||
child.alignTo(r, position);
|
||||
child.alignIn(r, position);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -182,8 +182,8 @@ Phaser.Component.Bounds.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Aligns this Game Object to another Game Object, or Rectangle (known as the
|
||||
* 'container'), into one of 9 possible positions.
|
||||
* Aligns this Game Object within another Game Object, or Rectangle, known as the
|
||||
* 'container', to one of 9 possible positions.
|
||||
*
|
||||
* The container must be a Game Object, or Phaser.Rectangle object. This can include properties
|
||||
* such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world
|
||||
|
@ -195,8 +195,8 @@ Phaser.Component.Bounds.prototype = {
|
|||
*
|
||||
* The position constants you can use are:
|
||||
*
|
||||
* `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.MIDDLE_LEFT`,
|
||||
* `Phaser.MIDDLE_CENTER`, `Phaser.MIDDLE_RIGHT`, `Phaser.BOTTOM_LEFT`,
|
||||
* `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`,
|
||||
* `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`,
|
||||
* `Phaser.BOTTOM_CENTER` and `Phaser.BOTTOM_RIGHT`.
|
||||
*
|
||||
* The Game Objects are placed in such a way that their _bounds_ align with the
|
||||
|
@ -215,12 +215,12 @@ Phaser.Component.Bounds.prototype = {
|
|||
*
|
||||
* @method
|
||||
* @param {Phaser.Rectangle|Phaser.Sprite|Phaser.Image|Phaser.Text|Phaser.BitmapText|Phaser.Button|Phaser.Graphics|Phaser.TileSprite} container - The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`.
|
||||
* @param {integer} [position] - The position constant. One of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.MIDDLE_LEFT`, `Phaser.MIDDLE_CENTER`, `Phaser.MIDDLE_RIGHT`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`.
|
||||
* @param {integer} [position] - The position constant. One of `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`, `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`.
|
||||
* @param {integer} [offsetX=0] - A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
|
||||
* @param {integer} [offsetY=0] - A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
|
||||
* @return {Object} This Game Object.
|
||||
*/
|
||||
alignTo: function (container, position, offsetX, offsetY) {
|
||||
alignIn: function (container, position, offsetX, offsetY) {
|
||||
|
||||
if (offsetX === undefined) { offsetX = 0; }
|
||||
if (offsetY === undefined) { offsetY = 0; }
|
||||
|
@ -243,17 +243,17 @@ Phaser.Component.Bounds.prototype = {
|
|||
this.top = container.top - offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.MIDDLE_LEFT:
|
||||
case Phaser.LEFT_CENTER:
|
||||
this.left = container.left - offsetX;
|
||||
this.centerY = container.centerY + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.MIDDLE_CENTER:
|
||||
case Phaser.CENTER:
|
||||
this.centerX = container.centerX + offsetX;
|
||||
this.centerY = container.centerY + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.MIDDLE_RIGHT:
|
||||
case Phaser.RIGHT_CENTER:
|
||||
this.right = container.right + offsetX;
|
||||
this.centerY = container.centerY + offsetY;
|
||||
break;
|
||||
|
@ -276,6 +276,119 @@ Phaser.Component.Bounds.prototype = {
|
|||
|
||||
return this;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Aligns this Game Object to the side of another Game Object, or Rectangle, known as the
|
||||
* 'parent', in one of 11 possible positions.
|
||||
*
|
||||
* The parent must be a Game Object, or Phaser.Rectangle object. This can include properties
|
||||
* such as `World.bounds` or `Camera.view`, for aligning Game Objects within the world
|
||||
* and camera bounds. Or it can include other Sprites, Images, Text objects, BitmapText,
|
||||
* TileSprites or Buttons.
|
||||
*
|
||||
* Please note that aligning a Sprite to another Game Object does **not** make it a child of
|
||||
* the parent. It simply modifies its position coordinates so it aligns with it.
|
||||
*
|
||||
* The position constants you can use are:
|
||||
*
|
||||
* `Phaser.TOP_LEFT` (default), `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`,
|
||||
* `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`,
|
||||
* `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER`
|
||||
* and `Phaser.BOTTOM_RIGHT`.
|
||||
*
|
||||
* The Game Objects are placed in such a way that their _bounds_ align with the
|
||||
* parent, taking into consideration rotation, scale and the anchor property.
|
||||
* This allows you to neatly align Game Objects, irrespective of their position value.
|
||||
*
|
||||
* The optional `offsetX` and `offsetY` arguments allow you to apply extra spacing to the final
|
||||
* aligned position of the Game Object. For example:
|
||||
*
|
||||
* `sprite.alignTo(background, Phaser.BOTTOM_RIGHT, -20, -20)`
|
||||
*
|
||||
* Would align the `sprite` to the bottom-right, but moved 20 pixels in from the corner.
|
||||
* Think of the offsets as applying an adjustment to the parents bounds before the alignment takes place.
|
||||
* So providing a negative offset will 'shrink' the parent bounds by that amount, and providing a positive
|
||||
* one expands it.
|
||||
*
|
||||
* @method
|
||||
* @param {Phaser.Rectangle|Phaser.Sprite|Phaser.Image|Phaser.Text|Phaser.BitmapText|Phaser.Button|Phaser.Graphics|Phaser.TileSprite} parent - The Game Object or Rectangle with which to align this Game Object to. Can also include properties such as `World.bounds` or `Camera.view`.
|
||||
* @param {integer} [position] - The position constant. One of `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_TOP`, `Phaser.LEFT_CENTER`, `Phaser.LEFT_BOTTOM`, `Phaser.RIGHT_TOP`, `Phaser.RIGHT_CENTER`, `Phaser.RIGHT_BOTTOM`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER` or `Phaser.BOTTOM_RIGHT`.
|
||||
* @param {integer} [offsetX=0] - A horizontal adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
|
||||
* @param {integer} [offsetY=0] - A vertical adjustment of the Containers bounds, applied to the aligned position of the Game Object. Use a negative value to shrink the bounds, positive to increase it.
|
||||
* @return {Object} This Game Object.
|
||||
*/
|
||||
alignTo: function (parent, position, offsetX, offsetY) {
|
||||
|
||||
if (offsetX === undefined) { offsetX = 0; }
|
||||
if (offsetY === undefined) { offsetY = 0; }
|
||||
|
||||
switch (position)
|
||||
{
|
||||
default:
|
||||
case Phaser.TOP_LEFT:
|
||||
this.left = parent.left - offsetX;
|
||||
this.bottom = parent.top - offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.TOP_CENTER:
|
||||
this.centerX = parent.centerX + offsetX;
|
||||
this.bottom = parent.top - offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.TOP_RIGHT:
|
||||
this.right = parent.right + offsetX;
|
||||
this.bottom = parent.top - offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.LEFT_TOP:
|
||||
this.right = parent.left - offsetX;
|
||||
this.top = parent.top + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.LEFT_CENTER:
|
||||
this.right = parent.left - offsetX;
|
||||
this.centerY = parent.centerY + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.LEFT_BOTTOM:
|
||||
this.right = parent.left - offsetX;
|
||||
this.bottom = parent.bottom + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.RIGHT_TOP:
|
||||
this.left = parent.right + offsetX;
|
||||
this.top = parent.top + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.RIGHT_CENTER:
|
||||
this.left = parent.right + offsetX;
|
||||
this.centerY = parent.centerY + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.RIGHT_BOTTOM:
|
||||
this.left = parent.right + offsetX;
|
||||
this.bottom = parent.bottom + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.BOTTOM_LEFT:
|
||||
this.left = parent.left - offsetX;
|
||||
this.top = parent.bottom + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.BOTTOM_CENTER:
|
||||
this.centerX = parent.centerX + offsetX;
|
||||
this.top = parent.bottom + offsetY;
|
||||
break;
|
||||
|
||||
case Phaser.BOTTOM_RIGHT:
|
||||
this.right = parent.right + offsetX;
|
||||
this.top = parent.bottom + offsetY;
|
||||
break;
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -384,28 +384,26 @@ Phaser.Rectangle.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Returns a point based on the given location constant.
|
||||
* Returns a point based on the given position constant, which can be one of:
|
||||
*
|
||||
* Which can be one of:
|
||||
*
|
||||
* `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.MIDDLE_LEFT`,
|
||||
* `Phaser.MIDDLE_CENTER`, `Phaser.MIDDLE_RIGHT`, `Phaser.BOTTOM_LEFT`,
|
||||
* `Phaser.BOTTOM_CENTER` and `Phaser.BOTTOM_RIGHT`.
|
||||
* `Phaser.TOP_LEFT`, `Phaser.TOP_CENTER`, `Phaser.TOP_RIGHT`, `Phaser.LEFT_CENTER`,
|
||||
* `Phaser.CENTER`, `Phaser.RIGHT_CENTER`, `Phaser.BOTTOM_LEFT`, `Phaser.BOTTOM_CENTER`
|
||||
* and `Phaser.BOTTOM_RIGHT`.
|
||||
*
|
||||
* This method returns the same values as calling Rectangle.bottomLeft, etc, but those
|
||||
* calls always create a new Point object, where-as this one allows you to use your own.
|
||||
*
|
||||
* @method Phaser.Rectangle#getPoint
|
||||
* @param {integer} [location] - One of the Phaser location constants, such as `Phaser.TOP_RIGHT`.
|
||||
* @param {integer} [position] - One of the Phaser position constants, such as `Phaser.TOP_RIGHT`.
|
||||
* @param {Phaser.Point} [out] - A Phaser.Point that the values will be set in.
|
||||
* If no object is provided a new Phaser.Point object will be created. In high performance areas avoid this by re-using an existing object.
|
||||
* @return {Phaser.Point} An object containing the point in its `x` and `y` properties.
|
||||
*/
|
||||
getPoint: function (location, out) {
|
||||
getPoint: function (position, out) {
|
||||
|
||||
if (out === undefined) { out = new Phaser.Point(); }
|
||||
|
||||
switch (location)
|
||||
switch (position)
|
||||
{
|
||||
default:
|
||||
case Phaser.TOP_LEFT:
|
||||
|
@ -417,13 +415,13 @@ Phaser.Rectangle.prototype = {
|
|||
case Phaser.TOP_RIGHT:
|
||||
return out.set(this.right, this.y);
|
||||
|
||||
case Phaser.MIDDLE_LEFT:
|
||||
case Phaser.LEFT_CENTER:
|
||||
return out.set(this.x, this.centerY);
|
||||
|
||||
case Phaser.MIDDLE_CENTER:
|
||||
case Phaser.CENTER:
|
||||
return out.set(this.centerX, this.centerY);
|
||||
|
||||
case Phaser.MIDDLE_RIGHT:
|
||||
case Phaser.RIGHT_CENTER:
|
||||
return out.set(this.right, this.centerY);
|
||||
|
||||
case Phaser.BOTTOM_LEFT:
|
||||
|
|
|
@ -337,16 +337,59 @@ Phaser.Physics.Arcade.Body = function (sprite) {
|
|||
*/
|
||||
this.syncBounds = false;
|
||||
|
||||
// Move to a 'movement' object?
|
||||
/**
|
||||
* @property {boolean} isMoving - Set by the `moveTo` and `moveFrom` methods.
|
||||
*/
|
||||
this.isMoving = false;
|
||||
|
||||
/**
|
||||
* @property {boolean} stopVelocityOnCollide - Set by the `moveTo` and `moveFrom` methods.
|
||||
*/
|
||||
this.stopVelocityOnCollide = true;
|
||||
|
||||
/**
|
||||
* @property {integer} moveTimer - Internal time used by the `moveTo` and `moveFrom` methods.
|
||||
* @private
|
||||
*/
|
||||
this.moveTimer = 0;
|
||||
|
||||
/**
|
||||
* @property {integer} moveDistance - Internal distance value, used by the `moveTo` and `moveFrom` methods.
|
||||
* @private
|
||||
*/
|
||||
this.moveDistance = 0;
|
||||
|
||||
/**
|
||||
* @property {integer} moveDuration - Internal duration value, used by the `moveTo` and `moveFrom` methods.
|
||||
* @private
|
||||
*/
|
||||
this.moveDuration = 0;
|
||||
this.moveTarget = new Phaser.Line();
|
||||
this.moveEnd = new Phaser.Point();
|
||||
|
||||
/**
|
||||
* @property {Phaser.Line} moveTarget - Set by the `moveTo` method, and updated each frame.
|
||||
* @private
|
||||
*/
|
||||
this.moveTarget = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} moveEnd - Set by the `moveTo` method, and updated each frame.
|
||||
* @private
|
||||
*/
|
||||
this.moveEnd = null;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Signal} onMoveComplete - Listen for the completion of `moveTo` or `moveFrom` events.
|
||||
*/
|
||||
this.onMoveComplete = new Phaser.Signal();
|
||||
|
||||
/**
|
||||
* @property {function} movementCallback - Optional callback. If set, invoked during the running of `moveTo` or `moveFrom` events.
|
||||
*/
|
||||
this.movementCallback = null;
|
||||
|
||||
/**
|
||||
* @property {object} movementCallbackContext - Context in which to call the movementCallback.
|
||||
*/
|
||||
this.movementCallbackContext = null;
|
||||
|
||||
/**
|
||||
|
@ -711,6 +754,8 @@ Phaser.Physics.Arcade.Body.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Note: This method is experimental, and may be changed or removed in a future release.
|
||||
*
|
||||
* This method moves the Body in the given direction, for the duration specified.
|
||||
* It works by setting the velocity on the Body, and an internal timer, and then
|
||||
* monitoring the duration each frame. When the duration is up the movement is
|
||||
|
@ -783,6 +828,8 @@ Phaser.Physics.Arcade.Body.prototype = {
|
|||
},
|
||||
|
||||
/**
|
||||
* Note: This method is experimental, and may be changed or removed in a future release.
|
||||
*
|
||||
* This method moves the Body in the given direction, for the duration specified.
|
||||
* It works by setting the velocity on the Body, and an internal distance counter.
|
||||
* The distance is monitored each frame. When the distance equals the distance
|
||||
|
@ -835,6 +882,12 @@ Phaser.Physics.Arcade.Body.prototype = {
|
|||
this.moveDuration = 0;
|
||||
this.moveDistance = distance;
|
||||
|
||||
if (this.moveTarget === null)
|
||||
{
|
||||
this.moveTarget = new Phaser.Line();
|
||||
this.moveEnd = new Phaser.Point();
|
||||
}
|
||||
|
||||
this.moveTarget.fromAngle(this.x, this.y, angle, distance);
|
||||
|
||||
this.moveEnd.set(this.moveTarget.end.x, this.moveTarget.end.y);
|
||||
|
|
29
typescript/phaser.d.ts
vendored
29
typescript/phaser.d.ts
vendored
|
@ -70,9 +70,17 @@ declare module "phaser" {
|
|||
static TOP_LEFT: number;
|
||||
static TOP_CENTER: number;
|
||||
static TOP_RIGHT: number;
|
||||
static MIDDLE_LEFT: number;
|
||||
static MIDDLE_CENTER: number;
|
||||
static MIDDLE_RIGHT: number;
|
||||
|
||||
static LEFT_TOP: number;
|
||||
static LEFT_CENTER: number;
|
||||
static LEFT_BOTTOM: number;
|
||||
|
||||
static CENTER: number;
|
||||
|
||||
static RIGHT_TOP: number;
|
||||
static RIGHT_CENTER: number;
|
||||
static RIGHT_BOTTOM: number;
|
||||
|
||||
static BOTTOM_LEFT: number;
|
||||
static BOTTOM_CENTER: number;
|
||||
static BOTTOM_RIGHT: number;
|
||||
|
@ -408,6 +416,7 @@ declare module "phaser" {
|
|||
y: number;
|
||||
z: number;
|
||||
|
||||
alignIn(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any;
|
||||
alignTo(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any;
|
||||
destroy(destroyChildren?: boolean): void;
|
||||
kill(): void;
|
||||
|
@ -1668,6 +1677,7 @@ declare module "phaser" {
|
|||
width: number;
|
||||
z: number;
|
||||
|
||||
alignIn(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any;
|
||||
alignTo(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any;
|
||||
destroy(destroyChildren?: boolean): void;
|
||||
drawTriangle(points: Phaser.Point[], cull?: boolean): void;
|
||||
|
@ -1844,6 +1854,7 @@ declare module "phaser" {
|
|||
world: Phaser.Point;
|
||||
z: number;
|
||||
|
||||
alignIn(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any;
|
||||
alignTo(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any;
|
||||
bringToTop(): Phaser.Image;
|
||||
crop(rect: Phaser.Rectangle, copy?: boolean): void;
|
||||
|
@ -2973,12 +2984,16 @@ declare module "phaser" {
|
|||
halfHeight: number;
|
||||
height: number;
|
||||
immovable: boolean;
|
||||
isMoving: boolean;
|
||||
mass: number;
|
||||
maxAngular: number;
|
||||
maxVelocity: Phaser.Point;
|
||||
moves: boolean;
|
||||
movementCallback: any;
|
||||
movementCallbackContext: any;
|
||||
newVelocity: Phaser.Point;
|
||||
offset: Phaser.Point;
|
||||
onMoveComplete: Phaser.Signal;
|
||||
overlapX: number;
|
||||
overlapY: number;
|
||||
phase: number;
|
||||
|
@ -2992,6 +3007,7 @@ declare module "phaser" {
|
|||
sourceHeight: number;
|
||||
speed: number;
|
||||
sprite: Phaser.Sprite;
|
||||
stopVelocityOnCollide: boolean;
|
||||
syncBounds: boolean;
|
||||
tilePadding: Phaser.Point;
|
||||
touching: FaceChoices;
|
||||
|
@ -3011,6 +3027,8 @@ declare module "phaser" {
|
|||
deltaAbsY(): number;
|
||||
destroy(): void;
|
||||
hitTest(x: number, y: number): boolean;
|
||||
moveFrom(duration: number, speed?: number, direction?: number): boolean;
|
||||
moveTo(duration: number, distance: number, direction?: number): boolean;
|
||||
onFloor(): boolean;
|
||||
onWall(): boolean;
|
||||
preUpdate(): void;
|
||||
|
@ -4096,7 +4114,7 @@ declare module "phaser" {
|
|||
equals(b: Phaser.Rectangle): boolean;
|
||||
floor(): void;
|
||||
floorAll(): void;
|
||||
getPoint(location: number, out: Phaser.Point): Phaser.Point;
|
||||
getPoint(position: number, out: Phaser.Point): Phaser.Point;
|
||||
inflate(dx: number, dy: number): Phaser.Rectangle;
|
||||
intersection(b: Phaser.Rectangle, out: Phaser.Rectangle): Phaser.Rectangle;
|
||||
intersects(b: Phaser.Rectangle, tolerance: number): boolean;
|
||||
|
@ -4535,6 +4553,7 @@ declare module "phaser" {
|
|||
y: number;
|
||||
z: number;
|
||||
|
||||
alignIn(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any;
|
||||
alignTo(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any;
|
||||
bringToTop(): Phaser.Sprite;
|
||||
crop(rect: Phaser.Rectangle, copy: boolean): void;
|
||||
|
@ -4886,6 +4905,7 @@ declare module "phaser" {
|
|||
addFontStyle(style: string, position: number): Phaser.Text;
|
||||
addFontWeight(weight: string, position: number): Phaser.Text;
|
||||
addStrokeColor(color: string, position: number): Phaser.Text;
|
||||
alignIn(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any;
|
||||
alignTo(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any;
|
||||
clearColors(): Phaser.Text;
|
||||
clearFontValues(): Phaser.Text;
|
||||
|
@ -5171,6 +5191,7 @@ declare module "phaser" {
|
|||
world: Phaser.Point;
|
||||
z: number;
|
||||
|
||||
alignIn(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any;
|
||||
alignTo(container: Phaser.Rectangle | Phaser.Sprite | Phaser.Image | Phaser.Text | Phaser.BitmapText | Phaser.Button | Phaser.Graphics | Phaser.TileSprite, position?: number, offsetX?: number, offsetY?: number): any;
|
||||
autoScroll(x: number, y: number): void;
|
||||
destroy(destroyChildren?: boolean): void;
|
||||
|
|
Loading…
Reference in a new issue