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) (FlxG.state.openSubState currentState)
(cc)) (cc))
(method :Void cleanup []
(FlxG.state.openSubState null))
(var STAGE_LEFT_X 150) (var STAGE_LEFT_X 150)
(var STAGE_RIGHT_X (- 1280 150)) (var STAGE_RIGHT_X (- 1280 150))
(var ACTOR_Y 500) (var ACTOR_Y 500)

View File

@@ -9,6 +9,11 @@
(setSprite.loadGraphic (dictGet sets set)) (setSprite.loadGraphic (dictGet sets set))
(newScene name (cast (new SceneFlxState setSprite time perspective))))) (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] (method newFlxSound [name path &opt :Float volume]
(set volume (or volume 1)) (set volume (or volume 1))
(assert (<= 0 volume 1)) (assert (<= 0 volume 1))

View File

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

View File

@@ -25,4 +25,6 @@ interface Director<Set, StagePosition, StageFacing, ScreenPosition, Actor, Sound
function showPropOnScreen(prop:Prop, position:ScreenPosition, cc:Continuation):Void; function showPropOnScreen(prop:Prop, position:ScreenPosition, cc:Continuation):Void;
// TODO showPropOnStage // TODO showPropOnStage
function hideProp(prop:Prop, cc:Continuation):Void; 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 // 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). // 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. // 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 :Map<String,Int> labelsByName (new Map))
(prop :Array<Int> labels []) (prop :Array<Int> labels [])
@@ -21,10 +22,17 @@
(dictSet labelsByName ,label ,idx) (dictSet labelsByName ,label ,idx)
(labels.push ,idx) (labels.push ,idx)
})] })]
`(method doPreload [:Void->Void cc] `{
(set isLoading true) (method doPreload [:Void->Void cc]
(collectedBlocks preload) (set isLoading true)
(set isLoading false) (collectedBlocks preload)
,@labelSetters (set isLoading false)
(cc)))) ,@labelSetters
(cc))
(method doCleanup []
(director.cleanup)
(set lastInstructionPointer -2)
(collectedBlocks cleanup))
(doCleanup)
}))
// TODO also &bof could call (doPreload) // TODO also &bof could call (doPreload)