mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 06:28:30 +00:00
Sprite.left, Sprite.right, Sprite.top, Sprite.bottom are new properties that contain the totals of the Sprite position and dimensions, adjusted for the anchor.
Sprite.offsetX and Sprite.offsetY contain the offsets from the Sprite.x/y coordinates to the top-left of the Sprite, taking anchor into consideration.
This commit is contained in:
parent
01a23b7d91
commit
8c23bca62d
4 changed files with 227 additions and 1 deletions
|
@ -100,6 +100,8 @@ Thanks to @pnstickne for vast majority of this update.
|
|||
* TilemapLayer.setScale will allow you to apply scaling to a specific Tilemap layer, i.e. `layer.setScale(2)` would double the size of the layer. The way the Camera responds to the layer is adjusted accordingly based on the scale, as is Arcade collision (thanks @mickez #1605)
|
||||
* SoundManager.setDecodedCallback lets you specify a list of Sound files, or keys, and a callback. Once all of the Sound files have finished decoding the callback will be invoked. The amount of time spent decoding depends on the codec used and file size. If all of the files given have already decoded the callback is triggered immediately.
|
||||
* Sound.loopFull is a new method that will start playback of the Sound and set it to loop in its entirety.
|
||||
* Sprite.left, Sprite.right, Sprite.top, Sprite.bottom are new properties that contain the totals of the Sprite position and dimensions, adjusted for the anchor.
|
||||
* Sprite.offsetX and Sprite.offsetY contain the offsets from the Sprite.x/y coordinates to the top-left of the Sprite, taking anchor into consideration.
|
||||
|
||||
### Updates
|
||||
|
||||
|
|
|
@ -1033,6 +1033,112 @@ Object.defineProperty(Phaser.Image.prototype, "smoothed", {
|
|||
|
||||
});
|
||||
|
||||
/**
|
||||
* The amount the image is visually offset from its x coordinate.
|
||||
* This is the same as `Image.width * Image.anchor.x`.
|
||||
* It will only be > 0 if the Image.anchor.x is not equal to zero.
|
||||
*
|
||||
* @name Phaser.Image#offsetX
|
||||
* @property {number} offsetX - The amount the image is visually offset from its x coordinate.
|
||||
* @readOnly
|
||||
*/
|
||||
Object.defineProperty(Phaser.Image.prototype, "offsetX", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.anchor.x * this.width;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The amount the image is visually offset from its y coordinate.
|
||||
* This is the same as `Image.height * Image.anchor.y`.
|
||||
* It will only be > 0 if the Image.anchor.y is not equal to zero.
|
||||
*
|
||||
* @name Phaser.Image#offsetY
|
||||
* @property {number} offsetY - The amount the image is visually offset from its y coordinate.
|
||||
* @readOnly
|
||||
*/
|
||||
Object.defineProperty(Phaser.Image.prototype, "offsetY", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.anchor.y * this.height;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The left coordinate of the Image, adjusted for the anchor.
|
||||
*
|
||||
* @name Phaser.Image#left
|
||||
* @property {number} left - The left coordinate of the Image, adjusted for the anchor.
|
||||
* @readOnly
|
||||
*/
|
||||
Object.defineProperty(Phaser.Image.prototype, "left", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.x - this.offsetX;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The right coordinate of the Image, adjusted for the anchor. This is the same as Image.x + Image.width - Image.offsetX.
|
||||
*
|
||||
* @name Phaser.Image#right
|
||||
* @property {number} right - The right coordinate of the Image, adjusted for the anchor. This is the same as Image.x + Image.width - Image.offsetX.
|
||||
* @readOnly
|
||||
*/
|
||||
Object.defineProperty(Phaser.Image.prototype, "right", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return (this.x + this.width) - this.offsetX;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The y coordinate of the Image, adjusted for the anchor.
|
||||
*
|
||||
* @name Phaser.Image#top
|
||||
* @property {number} top - The y coordinate of the Image, adjusted for the anchor.
|
||||
* @readOnly
|
||||
*/
|
||||
Object.defineProperty(Phaser.Image.prototype, "top", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.y - this.offsetY;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The sum of the y and height properties, adjusted for the anchor.
|
||||
*
|
||||
* @name Phaser.Image#bottom
|
||||
* @property {number} bottom - The sum of the y and height properties, adjusted for the anchor.
|
||||
* @readOnly
|
||||
*/
|
||||
Object.defineProperty(Phaser.Image.prototype, "bottom", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return (this.y + this.height) - this.offsetY;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.Image#destroyPhase
|
||||
* @property {boolean} destroyPhase - True if this object is currently being destroyed.
|
||||
|
|
|
@ -148,7 +148,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
|||
this.debug = false;
|
||||
|
||||
/**
|
||||
* @property {Phaser.Point} cameraOffset - If this object is fixedToCamera then this stores the x/y offset that its drawn at, from the top-left of the camera view.
|
||||
* @property {Phaser.Point} cameraOffset - If this object is fixedToCamera then this stores the x/y offset that it is drawn at. Values are relative to the top-left of the camera view.
|
||||
*/
|
||||
this.cameraOffset = new Phaser.Point();
|
||||
|
||||
|
@ -1354,6 +1354,112 @@ Object.defineProperty(Phaser.Sprite.prototype, "y", {
|
|||
|
||||
});
|
||||
|
||||
/**
|
||||
* The amount the sprite is visually offset from its x coordinate.
|
||||
* This is the same as `Sprite.width * Sprite.anchor.x`.
|
||||
* It will only be > 0 if the Sprite.anchor.x is not equal to zero.
|
||||
*
|
||||
* @name Phaser.Sprite#offsetX
|
||||
* @property {number} offsetX - The amount the sprite is visually offset from its x coordinate.
|
||||
* @readOnly
|
||||
*/
|
||||
Object.defineProperty(Phaser.Sprite.prototype, "offsetX", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.anchor.x * this.width;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The amount the sprite is visually offset from its y coordinate.
|
||||
* This is the same as `Sprite.height * Sprite.anchor.y`.
|
||||
* It will only be > 0 if the Sprite.anchor.y is not equal to zero.
|
||||
*
|
||||
* @name Phaser.Sprite#offsetY
|
||||
* @property {number} offsetY - The amount the sprite is visually offset from its y coordinate.
|
||||
* @readOnly
|
||||
*/
|
||||
Object.defineProperty(Phaser.Sprite.prototype, "offsetY", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.anchor.y * this.height;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The left coordinate of the Sprite, adjusted for the anchor.
|
||||
*
|
||||
* @name Phaser.Sprite#left
|
||||
* @property {number} left - The left coordinate of the Sprite, adjusted for the anchor.
|
||||
* @readOnly
|
||||
*/
|
||||
Object.defineProperty(Phaser.Sprite.prototype, "left", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.x - this.offsetX;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The right coordinate of the Sprite, adjusted for the anchor. This is the same as Sprite.x + Sprite.width - Sprite.offsetX.
|
||||
*
|
||||
* @name Phaser.Sprite#right
|
||||
* @property {number} right - The right coordinate of the Sprite, adjusted for the anchor. This is the same as Sprite.x + Sprite.width - Sprite.offsetX.
|
||||
* @readOnly
|
||||
*/
|
||||
Object.defineProperty(Phaser.Sprite.prototype, "right", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return (this.x + this.width) - this.offsetX;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The y coordinate of the Sprite, adjusted for the anchor.
|
||||
*
|
||||
* @name Phaser.Sprite#top
|
||||
* @property {number} top - The y coordinate of the Sprite, adjusted for the anchor.
|
||||
* @readOnly
|
||||
*/
|
||||
Object.defineProperty(Phaser.Sprite.prototype, "top", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return this.y - this.offsetY;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* The sum of the y and height properties, adjusted for the anchor.
|
||||
*
|
||||
* @name Phaser.Sprite#bottom
|
||||
* @property {number} bottom - The sum of the y and height properties, adjusted for the anchor.
|
||||
* @readOnly
|
||||
*/
|
||||
Object.defineProperty(Phaser.Sprite.prototype, "bottom", {
|
||||
|
||||
get: function () {
|
||||
|
||||
return (this.y + this.height) - this.offsetY;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* @name Phaser.Sprite#destroyPhase
|
||||
* @property {boolean} destroyPhase - True if this object is currently being destroyed.
|
||||
|
|
12
typescript/phaser.d.ts
vendored
12
typescript/phaser.d.ts
vendored
|
@ -1494,6 +1494,7 @@ declare module Phaser {
|
|||
anchor: Phaser.Point;
|
||||
animations: Phaser.AnimationManager;
|
||||
autoCull: boolean;
|
||||
bottom: number;
|
||||
cameraOffset: Phaser.Point;
|
||||
cropRect: Phaser.Rectangle;
|
||||
debug: boolean;
|
||||
|
@ -1512,11 +1513,16 @@ declare module Phaser {
|
|||
inputEnabled: boolean;
|
||||
inWorld: boolean;
|
||||
key: string|Phaser.RenderTexture|Phaser.BitmapData|PIXI.Texture;
|
||||
left: number;
|
||||
name: string;
|
||||
offsetX: number;
|
||||
offsetY: number;
|
||||
position: Phaser.Point;
|
||||
renderOrderID: number;
|
||||
right: number;
|
||||
scale: Phaser.Point;
|
||||
smoothed: boolean;
|
||||
top: number;
|
||||
type: number;
|
||||
world: Phaser.Point;
|
||||
z: number;
|
||||
|
@ -3789,6 +3795,7 @@ declare module Phaser {
|
|||
animations: Phaser.AnimationManager;
|
||||
autoCull: boolean;
|
||||
body: any;
|
||||
bottom: number;
|
||||
cameraOffset: Phaser.Point;
|
||||
checkWorldBounds: boolean;
|
||||
cropRect: Phaser.Rectangle;
|
||||
|
@ -3809,16 +3816,21 @@ declare module Phaser {
|
|||
inputEnabled: boolean;
|
||||
inWorld: boolean;
|
||||
key: string|Phaser.RenderTexture|Phaser.BitmapData|PIXI.Texture;
|
||||
left: number;
|
||||
lifespan: number;
|
||||
name: string;
|
||||
offsetX: number;
|
||||
offsetY: number;
|
||||
outOfBoundsKill: boolean;
|
||||
position: Phaser.Point;
|
||||
physicsEnabled: boolean;
|
||||
renderOrderID: number;
|
||||
right: number;
|
||||
scale: Phaser.Point;
|
||||
scaleMin: Phaser.Point;
|
||||
scaleMax: Phaser.Point;
|
||||
smoothed: boolean;
|
||||
top: number;
|
||||
type: number;
|
||||
world: Phaser.Point;
|
||||
x: number;
|
||||
|
|
Loading…
Add table
Reference in a new issue