Skip to content

Commit 30d73a0

Browse files
committed
Container can now be assigned an arcade physics body
1 parent f80db91 commit 30d73a0

2 files changed

Lines changed: 48 additions & 29 deletions

File tree

src/gameobjects/container/Container.js

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var Vector2 = require('../../math/Vector2');
2626
*
2727
* @extends Phaser.GameObjects.Components.Alpha
2828
* @extends Phaser.GameObjects.Components.BlendMode
29+
* @extends Phaser.GameObjects.Components.ComputedSize
2930
* @extends Phaser.GameObjects.Components.Depth
3031
* @extends Phaser.GameObjects.Components.Transform
3132
* @extends Phaser.GameObjects.Components.Visible
@@ -42,6 +43,7 @@ var Container = new Class({
4243
Mixins: [
4344
Components.Alpha,
4445
Components.BlendMode,
46+
Components.ComputedSize,
4547
Components.Depth,
4648
Components.Transform,
4749
Components.Visible,
@@ -130,28 +132,6 @@ var Container = new Class({
130132
*/
131133
this._sortKey = '';
132134

133-
/**
134-
* Internal value to allow Containers to be used for input.
135-
* Do not change this value. It has no effect other than to break input.
136-
*
137-
* @name Phaser.GameObjects.Container#displayOriginX
138-
* @type {number}
139-
* @private
140-
* @since 3.4.0
141-
*/
142-
this.displayOriginX = 0;
143-
144-
/**
145-
* Internal value to allow Containers to be used for input.
146-
* Do not change this value. It has no effect other than to break input.
147-
*
148-
* @name Phaser.GameObjects.Container#displayOriginY
149-
* @type {number}
150-
* @private
151-
* @since 3.4.0
152-
*/
153-
this.displayOriginY = 0;
154-
155135
/**
156136
* Internal value to allow Containers to be used for input.
157137
* Do not change this value. It has no effect other than to break input.
@@ -184,6 +164,42 @@ var Container = new Class({
184164
}
185165
},
186166

167+
/**
168+
* Internal value to allow Containers to be used for input and physics.
169+
* Do not change this value. It has no effect other than to break things.
170+
*
171+
* @name Phaser.GameObjects.Container#displayOriginX
172+
* @type {number}
173+
* @readOnly
174+
* @since 3.4.0
175+
*/
176+
displayOriginX: {
177+
178+
get: function ()
179+
{
180+
return this.width * 0.5;
181+
}
182+
183+
},
184+
185+
/**
186+
* Internal value to allow Containers to be used for input and physics.
187+
* Do not change this value. It has no effect other than to break things.
188+
*
189+
* @name Phaser.GameObjects.Container#displayOriginY
190+
* @type {number}
191+
* @readOnly
192+
* @since 3.4.0
193+
*/
194+
displayOriginY: {
195+
196+
get: function ()
197+
{
198+
return this.height * 0.5;
199+
}
200+
201+
},
202+
187203
/**
188204
* Does this Container exclusively manage its children?
189205
*

src/physics/arcade/Body.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ var Body = new Class({
5050

5151
function Body (world, gameObject)
5252
{
53+
var width = (gameObject.width) ? gameObject.width : 64;
54+
var height = (gameObject.height) ? gameObject.height : 64;
55+
5356
/**
5457
* [description]
5558
*
@@ -167,7 +170,7 @@ var Body = new Class({
167170
* @type {Phaser.Math.Vector2}
168171
* @since 3.0.0
169172
*/
170-
this.prev = new Vector2(this.position.x, this.position.y);
173+
this.prev = new Vector2(gameObject.x, gameObject.y);
171174

172175
/**
173176
* [description]
@@ -204,7 +207,7 @@ var Body = new Class({
204207
* @type {number}
205208
* @since 3.0.0
206209
*/
207-
this.width = gameObject.width;
210+
this.width = width;
208211

209212
/**
210213
* [description]
@@ -213,7 +216,7 @@ var Body = new Class({
213216
* @type {number}
214217
* @since 3.0.0
215218
*/
216-
this.height = gameObject.height;
219+
this.height = height;
217220

218221
/**
219222
* [description]
@@ -222,7 +225,7 @@ var Body = new Class({
222225
* @type {number}
223226
* @since 3.0.0
224227
*/
225-
this.sourceWidth = gameObject.width;
228+
this.sourceWidth = width;
226229

227230
/**
228231
* [description]
@@ -231,7 +234,7 @@ var Body = new Class({
231234
* @type {number}
232235
* @since 3.0.0
233236
*/
234-
this.sourceHeight = gameObject.height;
237+
this.sourceHeight = height;
235238

236239
if (gameObject.frame)
237240
{
@@ -246,7 +249,7 @@ var Body = new Class({
246249
* @type {number}
247250
* @since 3.0.0
248251
*/
249-
this.halfWidth = Math.abs(gameObject.width / 2);
252+
this.halfWidth = Math.abs(width / 2);
250253

251254
/**
252255
* [description]
@@ -255,7 +258,7 @@ var Body = new Class({
255258
* @type {number}
256259
* @since 3.0.0
257260
*/
258-
this.halfHeight = Math.abs(gameObject.height / 2);
261+
this.halfHeight = Math.abs(height / 2);
259262

260263
/**
261264
* [description]

0 commit comments

Comments
 (0)