Skip to content

Commit 53425bd

Browse files
committed
Matter Image and Matter Sprite didn't define a destroy method, causing an error when trying to destroy the parent Game Object. Fix phaserjs#3516
1 parent 70c7732 commit 53425bd

4 files changed

Lines changed: 9 additions & 22 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
* Calling Impact.World.remove(body) during a Body.updateCallback would cause the internal loop to crash when trying to access a now missing body. Two extra checks are in place to avoid this (thanks @iamDecode)
7777
* If `setInteractive` is called on a Game Object that fails to set a hit area, it will no longer try to assign `dropZone` to an undefined `input` property.
7878
* The Matter SetBody Component will no longer try to call `setOrigin` unless the Game Object has the origin component (which not all do, like Graphics and Container)
79+
* Matter Image and Matter Sprite didn't define a `destroy` method, causing an error when trying to destroy the parent Game Object. Fix #3516 (thanks @RollinSafary)
7980

8081
### Updates
8182

src/physics/matter-js/MatterImage.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,13 @@ var MatterImage = new Class({
113113

114114
var shape = GetFastValue(options, 'shape', null);
115115

116-
if (!shape)
116+
if (shape)
117117
{
118-
this.body = Bodies.rectangle(x, y, this.width, this.height, options);
119-
120-
this.body.gameObject = this;
121-
122-
if (GetFastValue(options, 'addToWorld', true))
123-
{
124-
world.add(this.body);
125-
}
118+
this.setBody(shape, options);
126119
}
127120
else
128121
{
129-
this.setBody(shape, options);
122+
this.setRectangle(this.width, this.height, options)
130123
}
131124

132125
this.setPosition(x, y);

src/physics/matter-js/MatterSprite.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,13 @@ var MatterSprite = new Class({
120120

121121
var shape = GetFastValue(options, 'shape', null);
122122

123-
if (!shape)
123+
if (shape)
124124
{
125-
this.body = Bodies.rectangle(x, y, this.width, this.height, options);
126-
127-
this.body.gameObject = this;
128-
129-
if (GetFastValue(options, 'addToWorld', true))
130-
{
131-
world.add(this.body);
132-
}
125+
this.setBody(shape, options);
133126
}
134127
else
135128
{
136-
this.setBody(shape, options);
129+
this.setRectangle(this.width, this.height, options)
137130
}
138131

139132
this.setPosition(x, y);

src/physics/matter-js/components/SetBody.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ var SetBody = {
114114

115115
var _this = this;
116116

117-
this.body.destroy = function ()
117+
body.destroy = function destroy ()
118118
{
119119
_this.world.remove(_this.body);
120120
_this.body.gameObject = null;
121121
};
122122

123123
if (addToWorld)
124124
{
125-
this.world.add(this.body);
125+
this.world.add(body);
126126
}
127127

128128
if (this._originComponent)

0 commit comments

Comments
 (0)