Game Objects including Sprite, Image, Particle, TilemapLayer, Text, BitmapText and TileSprite have a new property called data. This is an empty Object that Phaser will never touch internally, but your own code, or Phaser Plugins, can store Game Object specific data within it. This allows you to associate data with a Game Object without having to pollute or change its class shape.

This commit is contained in:
Richard Davey 2016-06-03 01:08:32 +01:00
parent 1b7dcd9cbb
commit 097add1aa6
4 changed files with 19 additions and 0 deletions

View file

@ -342,6 +342,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
* Animation.reverse will reverse the currently playing animation direction (thanks @gotenxds #2505)
* Animation.reverseOnce will reverse the animation direction for the current, or next animation only (thanks @gotenxds #2505)
* The way the display list updates and Camera movements are handled has been completely revamped, which should result is significantly smoother motion when the Camera is following tweened or physics controlled sprites. The `Stage.postUpdate` function is now vastly reduced in complexity. It takes control over updating the display list (calling `updateTransform` on itself), rather than letting the Canvas or WebGL renderers do this. Because of this change, the `Camera.updateTarget` function uses the Sprites `worldPosition` property instead, which is now frame accurate (thanks @whig @Upperfoot @Whoisnt @hexus #2482)
* Game Objects including Sprite, Image, Particle, TilemapLayer, Text, BitmapText and TileSprite have a new property called `data`. This is an empty Object that Phaser will never touch internally, but your own code, or Phaser Plugins, can store Game Object specific data within it. This allows you to associate data with a Game Object without having to pollute or change its class shape.
### Updates

View file

@ -147,6 +147,16 @@ Phaser.Component.Core.prototype = {
*/
name: '',
/**
* An empty Object that belongs to this Game Object.
* This value isn't ever used internally by Phaser, but may be used by your own code, or
* by Phaser Plugins, to store data that needs to be associated with the Game Object,
* without polluting the Game Object directly.
* @property {Object} data
* @default
*/
data: {},
/**
* The components this Game Object has installed.
* @property {object} components

View file

@ -127,6 +127,8 @@ Phaser.Component.Destroy.prototype = {
this.mask = null;
this.game = null;
this.data = {};
// In case Pixi is still going to try and render it even though destroyed
this.renderable = false;

View file

@ -339,6 +339,7 @@ declare module "phaser" {
bottom: number;
cameraOffset: Phaser.Point;
checkWorldBounds: boolean;
data: any;
destroyPhase: boolean;
debug: boolean;
dirty: boolean;
@ -1598,6 +1599,7 @@ declare module "phaser" {
cameraOffset: Phaser.Point;
checkWorldBounds: boolean;
components: any;
data: any;
debug: boolean;
destroyPhase: boolean;
exists: boolean;
@ -1761,6 +1763,7 @@ declare module "phaser" {
components: any;
cropRect: Phaser.Rectangle;
customRender: boolean;
data: any;
debug: boolean;
deltaX: number;
deltaY: number;
@ -4426,6 +4429,7 @@ declare module "phaser" {
components: any;
cropRect: Phaser.Rectangle;
customRender: boolean;
data: any;
debug: boolean;
deltaX: number;
deltaY: number;
@ -4986,6 +4990,7 @@ declare module "phaser" {
collisionHeight: number;
collisionWidth: number;
context: CanvasRenderingContext2D;
data: any;
debug: boolean;
debugAlpha: number;
debugCallbackColor: string;
@ -5073,6 +5078,7 @@ declare module "phaser" {
checkWorldBounds: boolean;
components: any;
customRender: boolean;
data: any;
debug: boolean;
destroyPhase: boolean;
events: Phaser.Events;