From 097add1aa6587b85a4d7ec2ebfe60cbf1569744c Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Fri, 3 Jun 2016 01:08:32 +0100 Subject: [PATCH] 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. --- README.md | 1 + src/gameobjects/components/Core.js | 10 ++++++++++ src/gameobjects/components/Destroy.js | 2 ++ typescript/phaser.d.ts | 6 ++++++ 4 files changed, 19 insertions(+) diff --git a/README.md b/README.md index 6c2a346eb..6b1585780 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/gameobjects/components/Core.js b/src/gameobjects/components/Core.js index 1bc807d41..2ed6f9589 100644 --- a/src/gameobjects/components/Core.js +++ b/src/gameobjects/components/Core.js @@ -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 diff --git a/src/gameobjects/components/Destroy.js b/src/gameobjects/components/Destroy.js index 88e395a99..a5aae95ac 100644 --- a/src/gameobjects/components/Destroy.js +++ b/src/gameobjects/components/Destroy.js @@ -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; diff --git a/typescript/phaser.d.ts b/typescript/phaser.d.ts index 2cafaee6b..5b0d37312 100644 --- a/typescript/phaser.d.ts +++ b/typescript/phaser.d.ts @@ -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;