Skip to content

Commit a943c07

Browse files
committed
FlxNapeSpace: properly handle and destroy plugin instance
1 parent e7350a9 commit a943c07

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

flixel/addons/nape/FlxNapeSpace.hx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ private class GraphicNapeDebug extends BitmapData {}
2323
*/
2424
class FlxNapeSpace extends FlxBasic
2525
{
26+
/**
27+
* The instance of the global FlxNapeSpace plugin, created when calling init()
28+
*/
29+
public static var instance:FlxNapeSpace;
30+
2631
public static var space:Space;
2732

2833
/**
@@ -64,10 +69,19 @@ class FlxNapeSpace extends FlxBasic
6469
*/
6570
public static function init():Void
6671
{
72+
if (instance != null)
73+
{
74+
FlxG.plugins.remove(instance);
75+
instance.destroy();
76+
instance = null;
77+
}
78+
79+
instance = new FlxNapeSpace();
80+
6781
#if (flixel < version("5.6.0"))
68-
FlxG.plugins.add(new FlxNapeSpace());
82+
FlxG.plugins.add(instance);
6983
#else
70-
FlxG.plugins.addPlugin(new FlxNapeSpace());
84+
FlxG.plugins.addPlugin(instance);
7185
#end
7286

7387
if (space == null)

0 commit comments

Comments
 (0)