destroy SceneFlxStates when a FlxMovie ends

This commit is contained in:
2021-12-21 16:37:38 -07:00
parent e1f2043ecc
commit fd4b989d17
5 changed files with 26 additions and 13 deletions

View File

@@ -22,6 +22,9 @@
(FlxG.state.openSubState currentState)
(cc))
(method :Void cleanup []
(FlxG.state.openSubState null))
(var STAGE_LEFT_X 150)
(var STAGE_RIGHT_X (- 1280 150))
(var ACTOR_Y 500)

View File

@@ -9,6 +9,11 @@
(setSprite.loadGraphic (dictGet sets set))
(newScene name (cast (new SceneFlxState setSprite time perspective)))))
// Destroy substates when the movie end is reached:
(cleanup
(doFor =>name scene scenes
(.destroy (cast scene SceneFlxState))))
(method newFlxSound [name path &opt :Float volume]
(set volume (or volume 1))
(assert (<= 0 volume 1))

View File

@@ -1,11 +1,6 @@
(prop &mut :FlxDirector director)
(prop &mut :FlxMovie movie)
(method &override :Void create []
(set destroySubStates false)
(super.create)
(set director (new FlxDirector))
(set movie (new FlxMovie director)))
(method &override :Void update [:Float elapsed]
(super.update elapsed))
(set director (new FlxDirector)))

View File

@@ -25,4 +25,6 @@ interface Director<Set, StagePosition, StageFacing, ScreenPosition, Actor, Sound
function showPropOnScreen(prop:Prop, position:ScreenPosition, cc:Continuation):Void;
// TODO showPropOnStage
function hideProp(prop:Prop, cc:Continuation):Void;
function cleanup():Void;
}

View File

@@ -1,7 +1,8 @@
// When this file is loaded, all expressions in (preload <...>) will be collected. When (end) is called, they will
// be injected into a method called (doPreload).
// This allows assets to be declared in Hollywoo files where they first appear, but still loaded before execution starts.
(collectBlocks preload (cc))
(collectBlocks preload (#when (StringTools.contains kissFile className) (cc)))
(collectBlocks cleanup (#when (StringTools.contains kissFile className) (cc)))
(prop :Map<String,Int> labelsByName (new Map))
(prop :Array<Int> labels [])
@@ -21,10 +22,17 @@
(dictSet labelsByName ,label ,idx)
(labels.push ,idx)
})]
`(method doPreload [:Void->Void cc]
(set isLoading true)
(collectedBlocks preload)
(set isLoading false)
,@labelSetters
(cc))))
`{
(method doPreload [:Void->Void cc]
(set isLoading true)
(collectedBlocks preload)
(set isLoading false)
,@labelSetters
(cc))
(method doCleanup []
(director.cleanup)
(set lastInstructionPointer -2)
(collectedBlocks cleanup))
(doCleanup)
}))
// TODO also &bof could call (doPreload)