Skip to content

Commit 5a620f9

Browse files
committed
Merge pull request phaserjs#1647 from pnstickne/wip-components-toproto
Moved component installation out of constructors
2 parents 2483cd5 + ee34327 commit 5a620f9

10 files changed

Lines changed: 184 additions & 164 deletions

File tree

src/gameobjects/BitmapText.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,28 @@ Phaser.BitmapText = function (game, x, y, font, text, size) {
6767

6868
PIXI.BitmapText.call(this, text);
6969

70-
Phaser.Utils.mixinPrototype(this, Phaser.Component.Core.prototype);
71-
72-
var components = [
73-
'Angle',
74-
'AutoCull',
75-
'Bounds',
76-
'Destroy',
77-
'FixedToCamera',
78-
'InputEnabled',
79-
'InWorld',
80-
'LifeSpan',
81-
'PhysicsBody',
82-
'Reset'
83-
];
84-
85-
Phaser.Component.Core.install.call(this, components);
8670
Phaser.Component.Core.init.call(this, game, x, y, '', null);
8771

8872
};
8973

9074
Phaser.BitmapText.prototype = Object.create(PIXI.BitmapText.prototype);
9175
Phaser.BitmapText.prototype.constructor = Phaser.BitmapText;
9276

77+
var components = [
78+
'Angle',
79+
'AutoCull',
80+
'Bounds',
81+
'Destroy',
82+
'FixedToCamera',
83+
'InputEnabled',
84+
'InWorld',
85+
'LifeSpan',
86+
'PhysicsBody',
87+
'Reset'
88+
];
89+
90+
Phaser.Component.Core.install.call(Phaser.BitmapText.prototype, components);
91+
9392
/**
9493
* @method Phaser.BitmapText.prototype.setStyle
9594
* @private

src/gameobjects/Graphics.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,28 @@ Phaser.Graphics = function (game, x, y) {
2727

2828
PIXI.Graphics.call(this);
2929

30-
Phaser.Utils.mixinPrototype(this, Phaser.Component.Core.prototype);
31-
32-
var components = [
33-
'Angle',
34-
'AutoCull',
35-
'Bounds',
36-
'Destroy',
37-
'FixedToCamera',
38-
'InputEnabled',
39-
'InWorld',
40-
'LifeSpan',
41-
'PhysicsBody',
42-
'Reset'
43-
];
44-
45-
Phaser.Component.Core.install.call(this, components);
4630
Phaser.Component.Core.init.call(this, game, x, y, '', null);
4731

4832
};
4933

5034
Phaser.Graphics.prototype = Object.create(PIXI.Graphics.prototype);
5135
Phaser.Graphics.prototype.constructor = Phaser.Graphics;
5236

37+
var components = [
38+
'Angle',
39+
'AutoCull',
40+
'Bounds',
41+
'Destroy',
42+
'FixedToCamera',
43+
'InputEnabled',
44+
'InWorld',
45+
'LifeSpan',
46+
'PhysicsBody',
47+
'Reset'
48+
];
49+
50+
Phaser.Component.Core.install.call(Phaser.Graphics.prototype, components);
51+
5352
/**
5453
* Automatically called by World.preUpdate.
5554
* @method Phaser.Graphics.prototype.preUpdate

src/gameobjects/Image.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,32 @@ Phaser.Image = function (game, x, y, key, frame) {
3232

3333
PIXI.Sprite.call(this, PIXI.TextureCache['__default']);
3434

35-
Phaser.Utils.mixinPrototype(this, Phaser.Component.Core.prototype);
36-
37-
var components = [
38-
'Angle',
39-
'Animation',
40-
'AutoCull',
41-
'Bounds',
42-
'BringToTop',
43-
'Crop',
44-
'Destroy',
45-
'FixedToCamera',
46-
'InputEnabled',
47-
'LifeSpan',
48-
'LoadTexture',
49-
'Overlap',
50-
'Reset',
51-
'Smoothed'
52-
];
53-
54-
Phaser.Component.Core.install.call(this, components);
5535
Phaser.Component.Core.init.call(this, game, x, y, key, frame);
5636

5737
};
5838

5939
Phaser.Image.prototype = Object.create(PIXI.Sprite.prototype);
6040
Phaser.Image.prototype.constructor = Phaser.Image;
6141

42+
var components = [
43+
'Angle',
44+
'Animation',
45+
'AutoCull',
46+
'Bounds',
47+
'BringToTop',
48+
'Crop',
49+
'Destroy',
50+
'FixedToCamera',
51+
'InputEnabled',
52+
'LifeSpan',
53+
'LoadTexture',
54+
'Overlap',
55+
'Reset',
56+
'Smoothed'
57+
];
58+
59+
Phaser.Component.Core.install.call(Phaser.Image.prototype, components);
60+
6261
Phaser.Image.prototype.preUpdateInWorld = Phaser.Component.InWorld.preUpdate;
6362
Phaser.Image.prototype.preUpdateCore = Phaser.Component.Core.preUpdate;
6463

src/gameobjects/Rope.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,37 +44,36 @@ Phaser.Rope = function (game, x, y, key, frame, points) {
4444

4545
PIXI.Rope.call(this, key, this.points);
4646

47-
Phaser.Utils.mixinPrototype(this, Phaser.Component.Core.prototype);
48-
49-
var components = [
50-
'Angle',
51-
'Animation',
52-
'AutoCull',
53-
'Bounds',
54-
'BringToTop',
55-
'Crop',
56-
'Delta',
57-
'Destroy',
58-
'FixedToCamera',
59-
'InputEnabled',
60-
'InWorld',
61-
'LifeSpan',
62-
'LoadTexture',
63-
'Overlap',
64-
'PhysicsBody',
65-
'Reset',
66-
'ScaleMinMax',
67-
'Smoothed'
68-
];
69-
70-
Phaser.Component.Core.install.call(this, components);
7147
Phaser.Component.Core.init.call(this, game, x, y, key, frame);
7248

7349
};
7450

7551
Phaser.Rope.prototype = Object.create(PIXI.Rope.prototype);
7652
Phaser.Rope.prototype.constructor = Phaser.Rope;
7753

54+
var components = [
55+
'Angle',
56+
'Animation',
57+
'AutoCull',
58+
'Bounds',
59+
'BringToTop',
60+
'Crop',
61+
'Delta',
62+
'Destroy',
63+
'FixedToCamera',
64+
'InputEnabled',
65+
'InWorld',
66+
'LifeSpan',
67+
'LoadTexture',
68+
'Overlap',
69+
'PhysicsBody',
70+
'Reset',
71+
'ScaleMinMax',
72+
'Smoothed'
73+
];
74+
75+
Phaser.Component.Core.install.call(Phaser.Rope.prototype, components);
76+
7877
Phaser.Rope.prototype.preUpdatePhysics = Phaser.Component.PhysicsBody.preUpdate;
7978
Phaser.Rope.prototype.preUpdateLifeSpan = Phaser.Component.LifeSpan.preUpdate;
8079
Phaser.Rope.prototype.preUpdateInWorld = Phaser.Component.InWorld.preUpdate;

src/gameobjects/Sprite.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,36 @@ Phaser.Sprite = function (game, x, y, key, frame) {
3535

3636
PIXI.Sprite.call(this, PIXI.TextureCache['__default']);
3737

38-
Phaser.Utils.mixinPrototype(this, Phaser.Component.Core.prototype);
39-
40-
var components = [
41-
'Angle',
42-
'Animation',
43-
'AutoCull',
44-
'Bounds',
45-
'BringToTop',
46-
'Crop',
47-
'Delta',
48-
'Destroy',
49-
'FixedToCamera',
50-
'InputEnabled',
51-
'InWorld',
52-
'LifeSpan',
53-
'LoadTexture',
54-
'Overlap',
55-
'PhysicsBody',
56-
'Reset',
57-
'ScaleMinMax',
58-
'Smoothed'
59-
];
60-
61-
Phaser.Component.Core.install.call(this, components);
6238
Phaser.Component.Core.init.call(this, game, x, y, key, frame);
6339

6440
};
6541

6642
Phaser.Sprite.prototype = Object.create(PIXI.Sprite.prototype);
6743
Phaser.Sprite.prototype.constructor = Phaser.Sprite;
6844

45+
var components = [
46+
'Angle',
47+
'Animation',
48+
'AutoCull',
49+
'Bounds',
50+
'BringToTop',
51+
'Crop',
52+
'Delta',
53+
'Destroy',
54+
'FixedToCamera',
55+
'InputEnabled',
56+
'InWorld',
57+
'LifeSpan',
58+
'LoadTexture',
59+
'Overlap',
60+
'PhysicsBody',
61+
'Reset',
62+
'ScaleMinMax',
63+
'Smoothed'
64+
];
65+
66+
Phaser.Component.Core.install.call(Phaser.Sprite.prototype, components);
67+
6968
Phaser.Sprite.prototype.preUpdatePhysics = Phaser.Component.PhysicsBody.preUpdate;
7069
Phaser.Sprite.prototype.preUpdateLifeSpan = Phaser.Component.LifeSpan.preUpdate;
7170
Phaser.Sprite.prototype.preUpdateInWorld = Phaser.Component.InWorld.preUpdate;

src/gameobjects/Text.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,6 @@ Phaser.Text = function (game, x, y, text, style) {
7676

7777
PIXI.Text.call(this, text, this.style);
7878

79-
Phaser.Utils.mixinPrototype(this, Phaser.Component.Core.prototype);
80-
81-
var components = [
82-
'Angle',
83-
'AutoCull',
84-
'Bounds',
85-
'BringToTop',
86-
'Destroy',
87-
'FixedToCamera',
88-
'InputEnabled',
89-
'InWorld',
90-
'LifeSpan',
91-
'Overlap',
92-
'PhysicsBody',
93-
'Reset',
94-
'Smoothed'
95-
];
96-
97-
Phaser.Component.Core.install.call(this, components);
9879
Phaser.Component.Core.init.call(this, game, x, y, '', null);
9980

10081
if (text !== ' ')
@@ -107,6 +88,24 @@ Phaser.Text = function (game, x, y, text, style) {
10788
Phaser.Text.prototype = Object.create(PIXI.Text.prototype);
10889
Phaser.Text.prototype.constructor = Phaser.Text;
10990

91+
var components = [
92+
'Angle',
93+
'AutoCull',
94+
'Bounds',
95+
'BringToTop',
96+
'Destroy',
97+
'FixedToCamera',
98+
'InputEnabled',
99+
'InWorld',
100+
'LifeSpan',
101+
'Overlap',
102+
'PhysicsBody',
103+
'Reset',
104+
'Smoothed'
105+
];
106+
107+
Phaser.Component.Core.install.call(Phaser.Text.prototype, components);
108+
110109
Phaser.Text.prototype.preUpdatePhysics = Phaser.Component.PhysicsBody.preUpdate;
111110
Phaser.Text.prototype.preUpdateLifeSpan = Phaser.Component.LifeSpan.preUpdate;
112111
Phaser.Text.prototype.preUpdateInWorld = Phaser.Component.InWorld.preUpdate;

src/gameobjects/TileSprite.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,31 @@ Phaser.TileSprite = function (game, x, y, width, height, key, frame) {
4242

4343
PIXI.TilingSprite.call(this, PIXI.TextureCache['__default'], width, height);
4444

45-
Phaser.Utils.mixinPrototype(this, Phaser.Component.Core.prototype);
46-
47-
var components = [
48-
'Angle',
49-
'Animation',
50-
'AutoCull',
51-
'Bounds',
52-
'Destroy',
53-
'FixedToCamera',
54-
'InputEnabled',
55-
'InWorld',
56-
'LoadTexture',
57-
'Overlap',
58-
'PhysicsBody',
59-
'Reset',
60-
'Smoothed'
61-
];
62-
63-
Phaser.Component.Core.install.call(this, components);
6445
Phaser.Component.Core.init.call(this, game, x, y, key, frame);
6546

6647
};
6748

6849
Phaser.TileSprite.prototype = Object.create(PIXI.TilingSprite.prototype);
6950
Phaser.TileSprite.prototype.constructor = Phaser.TileSprite;
7051

52+
var components = [
53+
'Angle',
54+
'Animation',
55+
'AutoCull',
56+
'Bounds',
57+
'Destroy',
58+
'FixedToCamera',
59+
'InputEnabled',
60+
'InWorld',
61+
'LoadTexture',
62+
'Overlap',
63+
'PhysicsBody',
64+
'Reset',
65+
'Smoothed'
66+
];
67+
68+
Phaser.Component.Core.install.call(Phaser.TileSprite.prototype, components);
69+
7170
Phaser.TileSprite.prototype.preUpdatePhysics = Phaser.Component.PhysicsBody.preUpdate;
7271
Phaser.TileSprite.prototype.preUpdateLifeSpan = Phaser.Component.LifeSpan.preUpdate;
7372
Phaser.TileSprite.prototype.preUpdateInWorld = Phaser.Component.InWorld.preUpdate;

0 commit comments

Comments
 (0)